Recently, Eva learned several advanced data structure techniques for trees. To show her progress, she asked Colin to give her a challenging problem about tree statistics.
However, Colin just gave her a very typical problem:
Given a tree with $$$n$$$ vertices, and vertex $$$1$$$ is the root. Each vertex has an integer weight $$$w_i$$$.
Let $$$lca(u,v)$$$ represent the lowest common ancestor of the vertices $$$u$$$ and $$$v$$$.
Given two integer sequences $$$a_1,a_2,\cdots,a_x~(1\le a_i\le n)$$$ and $$$b_1,b_2,\cdots,b_y~(1\le b_i\le n)$$$. Define the joint power of these two sequences to be $$$$$$ \sum_{i=1}^x\sum_{j=1}^yw_{lca(a_i,b_j)} $$$$$$
Please calculate the value of this joint power.
Eva thinks this problem is too easy, so she decided to change the problem into an online problem:
First, given the tree and the weight of each vertex. Initially, both sequences are empty.
Then there will be $$$m$$$ operations, each one is of the following two types:
After each operation, you need to output the current joint power of the two sequences.
However, this version of the problem is too hard for Eva, so she added an additional limitation that, after each operation, the sum of values in the first sequence will not exceed $$$10^6$$$. Now Eva turns this problem to you; do you know how to solve it?
The first line contains two integers $$$n,m~(1\le n,m\le 10^5)$$$, representing the number of vertices in the tree and the number of operations.
The second line contains $$$n$$$ integers $$$w_1,w_2,\cdots,w_n(1\le w_i\le 10^5)$$$, representing the weight of each vertex.
For the following $$$n-1$$$ lines, each line contains two integers $$$u_i,v_i~(1\le u_i,v_i\le n, u_i\ne v_i)$$$, representing that there is an edge connecting $$$u_i$$$ and $$$v_i$$$ in the tree. It's guaranteed that all the edges in the input form a tree.
For the following $$$m$$$ lines, each line contains two integers $$$op_i, u_i~(op_i\in\{1,2\},1\le u_i\le n)$$$, representing an operation. It's guaranteed that after each operation, the sum of values in the first sequence will not exceed $$$10^6$$$.
For each operation, output a single line with a single integer, representing the joint power of the two sequences after the corresponding operation.
3 51 2 31 21 31 12 11 22 21 3
0 1 2 5 7
10 61 2 10 5 5 6 5 6 2 21 22 31 44 52 63 76 82 96 102 101 72 51 91 52 6
0 2 3 6 12 17
| Name |
|---|


