#ds703. DFS序练习2

DFS序练习2

DFS Order Practice 2

Problem Description

Given a tree with nn vertices, each vertex has a weight wiw_i, and vertex 11 is the root. There are qq operations:

  1. 1 x y: change the weight of vertex xx to yy.
  2. 2 x: query the sum of weights in the subtree of vertex xx.
  3. 3 x: move the root to vertex xx.

Input Format

The first line contains two integers n,q (1≤n,q≤2×105)n, q\ (1 \le n, q \le 2 \times 10^5).

The next n−1n-1 lines each contain two integers u,vu, v, denoting an edge.

The next line contains nn integers w1,w2,…,wn (1≤wi≤109)w_1, w_2, \dots, w_n\ (1 \le w_i \le 10^9).

The next qq lines each describe one operation. It is guaranteed that 1≤x≤n, 1≤y≤1091 \le x \le n,\ 1 \le y \le 10^9.

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