#K42092. Taco Tree Queries
Taco Tree Queries
Taco Tree Queries
You are given a tree with N nodes numbered from 1 to N. Each node has an initial integer value. The tree is rooted at node 1. You will be given several queries of two types:
1 u k
: Increase the value of every node in the subtree of node u (including u itself) by k.2 u
: Query and output the current value of node u.
Definition: In a rooted tree, the subtree of a node consists of that node and all of its descendants.
Your task is to process the queries and output the results of all type 2 queries in the order they appear.
inputFormat
The input is read from standard input (stdin) in the following format:
N v1 v2 ... vN u1 v1 u2 v2 ... (N-1 lines representing the edges) Q query1 query2 ... (Q queries)
Where:
- N is the number of nodes.
- The second line contains N integers representing the initial values of the nodes.
- Each of the next N-1 lines contains two integers indicating an undirected edge between the given nodes.
- Q is the number of queries.
- Each of the next Q lines contains a query in one of the following formats:
1 u k
(update query)2 u
(query value)
outputFormat
For every query of type 2
, output the current value of the specified node on a new line (stdout).
5
1 2 3 4 5
1 2
1 3
3 4
3 5
3
1 3 10
2 4
2 1
14
1
</p>