On the mysterious continent of Ringza Ayu, there are $$$ n $$$ regions, numbered from $$$ 1 $$$ to $$$ n $$$. These $$$ n $$$ regions form a tree, meaning there are $$$ n-1 $$$ roads connecting these $$$ n $$$ regions, and for any two regions, there exists exactly one simple path that allows them to reach each other.
Initially, all $$$ n $$$ regions are uncolored. Each region can be in either a colored or uncolored state, and the pleasure value of the $$$ i $$$-th region in the uncolored state is $$$ a_i $$$. For a region, if it is currently uncolored and has a pleasure value of $$$ x $$$, then when it becomes colored, its pleasure value becomes $$$ 2 \times x $$$; if it is currently colored and has a pleasure value of $$$ x $$$, then when it becomes uncolored, its pleasure value becomes $$$\lfloor \frac{x}{2} \rfloor$$$.
Now, Boki-chan has given $$$ q $$$ operations, each of which is one of the following:
After each operation, Boki-chan wants to know the maximum pleasure value she can obtain by selecting several non-adjacent regions on the continent of Ringza Ayu.
First, input a single integer $$$ n (1 \leq n \leq 10^5) $$$, representing the number of regions.
Next, input a line with $$$ n $$$ integers $$$ a_1, a_2, \dots, a_n (1 \leq a_i \leq 10^9) $$$, where $$$ a_i $$$ denotes the pleasure value of the $$$ i $$$-th region in the uncolored state.
Then input $$$ n-1 $$$ lines, each containing two integers $$$ u, v (1 \leq u, v \leq n) $$$, representing a road between the $$$ u $$$-th region and the $$$ v $$$-th region $$$(u,v)$$$.
Next, input a single integer $$$ q (1 \leq q \leq 5 \times 10^4) $$$, representing the number of operations.
Following this, there are $$$ q $$$ lines, each containing two or three integers, representing an operation, specifically as follows:
It is guaranteed that the $$$ n $$$ regions form a tree.
Output $$$ q $$$ lines, each containing a single integer, representing the maximum pleasure value obtained after each operation by Boki-chan.
31 1 11 22 331 22 23 2 4
3 3 4
97 6 9 10 3 12 4 5 111 22 33 44 55 66 77 88 911 4
73
210 11 241 13 1 252 11 1
20 25 12 24
In the first sample, after the first operation, the $$$ 2 $$$-th region was dyed, and since $$$(\operatorname{lcm}(2,3))^2-(2+3) \times \operatorname{lcm}(2,3)=2 \times 3$$$, the $$$ 3 $$$-th region was also dyed. The pleasure values of the three regions are: $$$ 1, 2, 2 $$$, and Boki-chan can choose to obtain the pleasure values of the $$$ 1 $$$-th and $$$ 3 $$$-th regions, resulting in a total pleasure value of $$$ 3 $$$. It can be proven that this way maximizes the pleasure value for Boki-chan. After the second operation, according to the problem statement, the pleasure values of the three regions are: $$$ 1, 1, 2 $$$. Boki-chan can again choose to obtain the pleasure values of the $$$ 1 $$$-th and $$$ 3 $$$-th regions, resulting in a total pleasure value of $$$ 3 $$$. This way also maximizes the pleasure value for Boki-chan. After the third operation, the pleasure value of the $$$ 2 $$$-th region was modified to $$$ 4 $$$, and now the pleasure values of the three regions are: $$$ 1, 4, 2 $$$. Boki-chan can choose to obtain the pleasure value of the $$$ 2 $$$-th region, which maximizes her pleasure value.
In the second sample, after the first operation, the $$$ 4 $$$-th region was dyed, and since $$$ (\operatorname{lcm}(4,6))^2-(4+6) \times \operatorname{lcm}(4,6)=4 \times 6$$$, the $$$ 6 $$$-th region was also dyed, and because $$$ (\operatorname{lcm}(6,9))^2-(6+9) \times \operatorname{lcm}(6,9)=6 \times 9$$$, the $$$ 9 $$$-th region was also dyed. It is clear that $$$ (\operatorname{lcm}(6,4))^2-(6+4) \times \operatorname{lcm}(6,4)=6 \times 4$$$, and since the $$$ 4 $$$-th region has already been dyed, it will not be dyed again in this operation.
In the third sample, Boki-chan's optimal strategy is always to choose the pleasure value of the $$$ 1 $$$-th region. After the first operation, the pleasure value of the $$$ 1 $$$-th region becomes $$$ 20 $$$. After the second operation, the pleasure value of the $$$ 1 $$$-th region is modified to $$$ 25 $$$. After the third operation, since the state of the $$$ 1 $$$-th region changes from colored to uncolored, its pleasure value becomes $$$\lfloor \frac{25}{2} \rfloor = 12$$$. After the fourth operation, since the state of the $$$ 1 $$$-th region changes from uncolored to colored, its pleasure value becomes $$$ 12 \times 2 = 24$$$.
| Название |
|---|


