#P3178. [HAOI2015] 树上操作
[HAOI2015] 树上操作
Description
There is a tree with nodes, rooted at node , and each node has a weight. There are operations of three types:
- Operation : increase the weight of node by .
- Operation : increase the weight of every node in the subtree rooted at node by .
- Operation : query the sum of weights of all nodes on the path from node to the root.
Input Format
The first line contains two integers , representing the number of nodes and the number of operations.
The next line contains integers, representing the initial weights of the nodes.
Each of the next lines contains two positive integers , indicating that there is an edge in the tree.
Then there are lines, each describing one operation. The first number indicates the type of the operation, followed by the parameters of that operation.
Output Format
For each query operation, output the answer. Print each answer on a new line.
5 5
1 2 3 4 5
1 2
1 4
2 3
2 5
3 3
1 2 1
3 5
2 1 2
3 3
6
9
13
Hint
For of the testdata, , and the absolute values of all input numbers do not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号