#P2590. [ZJOI2008] 树的统计
[ZJOI2008] 树的统计
Description
There is a tree with nodes, numbered from to , and each node has a weight .
You are asked to perform the following operations on the tree:
I. CHANGE u t: Set the weight of node to .
II. QMAX u v: Query the maximum weight among the nodes on the path from to .
III. QSUM u v: Query the sum of the weights of the nodes on the path from to .
Note: The nodes on the path from to include and themselves.
Input Format
The first line contains an integer , the number of nodes.
The next lines each contain two integers and , indicating that there is an edge between node and node .
The next line contains integers, where the -th integer is the weight of node .
The next line contains an integer , the total number of operations.
The next lines each contain one operation, given as CHANGE u t, QMAX u v, or QSUM u v.
Output Format
For each QMAX or QSUM operation, output one integer on its own line representing the result.
4
1 2
2 3
4 1
4 2 1 3
12
QMAX 3 4
QMAX 3 3
QMAX 3 2
QMAX 2 3
QSUM 3 4
QSUM 2 1
CHANGE 1 5
QMAX 3 4
CHANGE 3 6
QMAX 3 4
QMAX 2 4
QSUM 3 4
4
1
2
2
10
6
5
6
5
16
Hint
Constraints:
For of the testdata, it is guaranteed that and .
Throughout the operations, each node’s weight is guaranteed to be between and .
Translated by ChatGPT 5
京公网安备 11011102002149号