#ds703. DFS序练习2
DFS序练习2
DFS Order Practice 2
Problem Description
Given a tree with vertices, each vertex has a weight , and vertex is the root. There are operations:
1 x y: change the weight of vertex to .2 x: query the sum of weights in the subtree of vertex .3 x: move the root to vertex .
Input Format
The first line contains two integers .
The next lines each contain two integers , denoting an edge.
The next line contains integers .
The next lines each describe one operation. It is guaranteed that .
Output Format
For each query operation (type 2), output one number: the answer.
Sample Input
5 6
1 2
2 3
2 4
3 5
1 2 3 4 5
2 3
1 2 10
3 3
2 3
3 5
2 3
Sample Output
8
23
18