#P8827. [传智杯 #3 初赛] 森林
[传智杯 #3 初赛] 森林
Description
Qingzhengyu is a dedicated forest ranger of YYH Land. He is responsible for maintaining the forest of YYH Land every day. At the very beginning, YYH Land has only one tree with nodes, and each node has a spiritual power value .
Since YYH Land is a magical country, the trees in YYH Land also have some magical abilities. Specifically, the following operations are supported:
-
1 e
The edge with index suddenly disappears, splitting the tree it belongs to into two trees. -
2 u val
The spiritual power value of the node with index becomes . -
3 u
Qingzhengyu makes a query: find the sum of spiritual power values of the tree that contains .
Now you need to help Qingzhengyu simulate the events above to understand how the forest changes.
Input Format
The first line contains , as described above.
The second line contains numbers, the initial weights of the nodes, each within .
The next lines each contain a pair , representing an edge. (It is guaranteed that initially it is a tree.)
The next lines contain operations:
First read an , indicating the operation type.
When , read , meaning to delete the -th input edge. (It is guaranteed that the -th edge exists.)
When , read , meaning to change the weight of node to ().
When , read , meaning to query the sum of node weights in the tree that contains .
Output Format
For each query operation, output one line with one number representing the answer.
2 3
1 1
1 2
2 2 4
1 1
3 2
4
Hint
For of the testdata, holds.
For of the testdata, holds.
For the other of the testdata, only operations and exist.
For of the testdata, , and hold.
Translated by ChatGPT 5
京公网安备 11011102002149号