#C3916. Tree Query Operations
Tree Query Operations
Tree Query Operations
You are given a rooted tree with n nodes where each node has an integer value. The tree is defined by n-1 directed edges, and node 1 is the root. You will be given a series of queries of two types:
- Type 1:
1 x inc
– Increment the value of every node in the subtree rooted at nodex
by an integerinc
. In other words, for every node u in the subtree of x (including x itself), update its value as follows: $$value_u = value_u + inc$$ - Type 2:
2 x
– Query the maximum value among all nodes in the subtree rooted at nodex
.
Your task is to process the queries in the given order and for every type 2 query, print the maximum value in the specified subtree.
inputFormat
Input Format:
- The first line contains an integer
n
, the number of nodes in the tree. - The second line contains
n
space-separated integers, where the i-th integer represents the initial value of node i. - Each of the next
n-1
lines contains two space-separated integersu v
, representing a directed edge from nodeu
(parent) to nodev
(child). - The next line contains an integer
q
, the number of queries. - Each of the following
q
lines represents a query in one of the following formats:1 x inc
for a type 1 query (increment operation).2 x
for a type 2 query (maximum value query).
outputFormat
Output Format:
For each query of type 2, print a single line containing the maximum value in the subtree rooted at the given node.
## sample5
1 2 3 4 5
1 2
1 3
3 4
3 5
4
2 3
1 3 2
2 3
2 1
5
7
7
</p>