QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 256 MB Puntuación total: 100

#15145. T2 / Operations on Trees

Estadísticas

Output 2

17

Note

In the second example, coloring nodes 1 and 2 yields the maximum profit.

Constraints

For 30% of the data, $N \le 20$. For 50% of the data, $N \le 100$. For 100% of the data, $0 \le K \le N$.

There is a tree with $N$ nodes, rooted at node 1, where each node has a weight. There are $M$ operations of three types:

Operation 1: Increase the weight of a node $x$ by $a$. Operation 2: Increase the weights of all nodes in the subtree rooted at $x$ by $a$. Operation 3: Query the sum of weights of all nodes on the path from node $x$ to the root.

Input

The first line contains two integers $N$ and $M$, representing the number of nodes and the number of operations. The next line contains $N$ integers, representing the initial weights of the nodes. The next $N-1$ lines each contain two positive integers $fr$ and $to$, representing an edge between $fr$ and $to$ in the tree. The next $M$ lines each describe an operation. The first number indicates the type of operation (1-3), followed by the parameters for that operation ($x$ or $x$ $a$).

Output

For each query operation, output the answer. Separate the answers with newlines.

Constraints

For 30% of the data, $N, M \le 1000$. For 50% of the data, $N, M \le 100000$ and the data is random. For 100% of the data, $N, M \le 100000$, and the absolute value of all input data will not exceed $10^6$.

Examples

Input 1

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

Output 1

6
9
13

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.