#P13567. 「CZOI-R5」折跃点
「CZOI-R5」折跃点
Background
An interstellar war has broken out in the universe.
Problem Description
To perform instant movement in the interstellar war, we have built warp points in the occupied star regions. All warp points form a rooted tree with warp point as the root. The energy value of warp point is .
We say that warp point can reach warp point after consecutive warps if and only if starting from warp point , after walking along edges we can arrive at warp point , and during the process the distance to warp point keeps strictly increasing or keeps strictly decreasing.
Now we need to perform maintenance operations of the following types:
- Space Energy Boost: For all warp points that can be reached from warp point after consecutive warps, add to their energy values.
- Warp Test: For all warp points that can be reached from warp point after consecutive warps, output the sum of their energy values.
Input Format
The first line contains integers .
The second line contains integers; the -th one is .
The next lines each contain integers , representing an edge.
The next lines each start with an integer , then:
- If , input integers , representing one Space Energy Boost.
- If , input integers , representing one Warp Test.
Output Format
Output several lines of integers, which are the results of all Warp Tests.
5 5
6 8 4 10 6
2 1
3 2
4 1
5 4
1 1 2 7
2 4 1
2 2 0
1 2 1 4
2 1 2
19
8
28
Hint
Sample Explanation

The tree is shown in the figure.
In the first operation, the warp points that satisfy the condition are warp points . After the operation, .
In the second operation, the warp points that satisfy the condition are warp points , and the answer is .
In the third operation, the warp point that satisfies the condition is warp point , and the answer is .
In the fourth operation, the warp points that satisfy the condition are warp points . After the operation, .
In the fifth operation, the warp points that satisfy the condition are warp points , and the answer is .
Constraints
This problem uses bundled testdata.
- Subtask #1 (): .
- Subtask #2 (): .
- Subtask #3 (): .
- Subtask #4 (): No special constraints.
For of the testdata, , , , , 。
Translated by ChatGPT 5