#P5649. Sone1
Sone1
Problem Description
You are given a rooted tree with nodes. Each node has a weight. There are operations in total, divided into 12 types:
0 x y: Set the weights of all nodes in the subtree of to .1 x: Change the root of the tree to node .2 x y z: Set the weights of all nodes on the simple path from to to .3 x: Query the minimum weight in the subtree of .4 x: Query the maximum weight in the subtree of .5 x y: Increase the weights of all nodes in the subtree of by .6 x y z: Add to the weights of all nodes on the simple path from to .7 x y: Query the minimum weight on the simple path from to .8 x y: Query the maximum weight on the simple path from to .9 x y: Change the parent of to . If is in the subtree of , ignore this operation.10 x y: Query the sum of weights on the simple path from to .11 x: Query the sum of weights in the subtree of .
Input Format
The first line contains two positive integers , representing the number of nodes and the number of operations.
The next lines each contain two positive integers , indicating there is an edge between and .
Then follow lines, each containing one integer, representing the node weight.
The next line contains one positive integer, representing the initial root.
Finally, there are lines, each containing several positive integers, representing one operation.
Output Format
For each operation of type , output one line with one integer, representing the answer.
5 5
2 1
3 1
4 1
5 2
4
1
4
1
2
1
10 2 3
3 1
7 3 4
6 3 3 2
9 5 1
9
1
1
10 12
2 1
3 2
4 2
5 3
6 4
7 5
8 2
9 4
10 9
791
868
505
658
860
623
393
717
410
173
4
0 8 800
1 4
2 8 2 103
3 9
4 4
5 7 304
6 8 8 410
7 10 8
8 1 8
9 6 9
10 2 3
11 5
173
860
103
791
608
1557
Hint
Source: BZOJ 3153
Constraints
For of the data, , and all intermediate computed values are within .
Since this problem is very hard to implement, you can click here to download the testdata. Submit after passing locally.
Translated by ChatGPT 5