#P11855. [CSP-J 2022 山东] 部署
[CSP-J 2022 山东] 部署
Background
Due to the impact of the pandemic, Shandong Province canceled the CSP-J 2022 certification event, and re-created the problems in March of the following year to hold a make-up contest within the province.
Problem Description
“Letters from afar never cease; beacon fires pass through five passes even in daylight.”
In ancient times, without modern information-based warfare technology, people could only rely on beacon fires to transmit messages and on generals to plan and deploy troops to gain an advantage in war.
To minimize consumption, Country A has now built roads and marching deployment routes among cities, such that all cities are mutually reachable and there are no cycles (i.e., they form a tree structure rooted at City ). Each city has a certain number of troops stationed.
To describe the problem clearly, we number these cities from to , and City is the root of the tree (the testdata guarantees that they form a tree rooted at City ). Initially, City has an initial troop count of .
Now, to test the speed of war deployment, the general performs tests. Each test is one of the following two commands:
1 x y (the three numbers are separated by exactly 1 space): add troops to City and to all cities in the subtree rooted at it.
2 x y (the three numbers are separated by exactly 1 space): add troops to City and to all cities directly connected to it (including its parent node and child nodes).
After issuing the commands, the general calls in an adviser and makes queries. Each query asks for the final troop count of City . That adviser is Xiao Xiamai, and he asks you for help again. Please help him solve the problem (the results of the queries).
Input Format
The first line contains a positive integer , indicating the number of cities.
The second line contains positive integers , indicating the initial troop count in each city.
The next lines each contain two integers , indicating that there is a road directly connecting cities and .
The next line contains a positive integer , indicating the number of commands.
The next lines each contain three positive integers , representing one of the two command types. When , it means the first command; when , it means the second command.
The next line contains a positive integer , indicating the number of queries.
The next lines each contain a positive integer , indicating a query for the final troop count of the city numbered .
Output Format
Output lines. Each line contains a positive integer, corresponding to the answer for each query.
5
1 2 3 4 5
1 2
1 3
2 4
3 5
4
1 1 2
2 2 3
1 3 3
2 5 1
4
1
2
3
4
6
7
9
9
4
1 1 1 1
1 2
1 3
1 4
1
1 1 1
2
1
2
2
2
Hint
Constraints
For of the testdata, .
For of the testdata, .
Among them, for of the testdata the tree is a chain; for another the testdata contains only operation ; for another the testdata contains only operation .
For of the testdata, it is guaranteed that the given cities and roads form a tree, and City is the root node. $1\le n\le10^{6},1\le m\le10^{6},1\le q\le10^{6},1\le a_{i}\le10^{9},1\le x\le n,1\le y\le10$.
Hack testdata set added on 2025-06-26.
Translated by ChatGPT 5