-->
当前位置:首页 > 题库

PROGRAMMING:the sum

Luz5年前 (2021-05-10)题库397
It is known that there are $$n $$nodes and $$n $- 1 edges, forming a tree structure
Given a root node $$s $$. Each node has a weight, and the weight of node $$I $$is $$VI $$
There are two types of operations
$$1 $$$a $$$x $$, which means adding $$X to the weight of node $$a $$$
$$2 $$$a $, which means to find the sum of all nodes in the subtree of the $$a $$node (including the $$a $$node itself)
###Input format:
The first line gives three positive integers, N, m, S. n is the number of nodes in the tree, M is the number of m groups of operations, and S is the root node of the tree
The second line gives n positive integers, and the ith positive integer represents the weight VI of the ith node
In the following n-1 line, each line has two positive integers u and V, representing an edge
Finally, m lines, each line gives an operation
1<=n,m<=$$10^6$$,1<=s<=n,$$-10^6$$<=vi,x<=$$10^6$$
###Output format:
For each operation of type 2, a positive integer is output to represent the sum of weights of all nodes of the subtree with a as root
###Input example:
Here is a set of inputs. For example:
```in
5 6 1
1 2 3 4 5
1 3
1 2
2 4
2 5
1 2 10
1 3 10
1 4 5
1 5 1
2 3
2 2
```
###Output example:
The corresponding output is given here. For example:
```out
thirteen
twenty-seven
```







answer:If there is no answer, please comment