#C3916. Tree Query Operations

    ID: 47396 Type: Default 1000ms 256MiB

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 node x by an integer inc. 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 node x.

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:

  1. The first line contains an integer n, the number of nodes in the tree.
  2. The second line contains n space-separated integers, where the i-th integer represents the initial value of node i.
  3. Each of the next n-1 lines contains two space-separated integers u v, representing a directed edge from node u (parent) to node v (child).
  4. The next line contains an integer q, the number of queries.
  5. 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.

## sample
5
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>