#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 nn nodes, and each node has a spiritual power value vv.

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 ee suddenly disappears, splitting the tree it belongs to into two trees.

  • 2 u val
    The spiritual power value of the node with index uu becomes valval.

  • 3 u
    Qingzhengyu makes a query: find the sum of spiritual power values of the tree that contains uu.

Now you need to help Qingzhengyu simulate the events above to understand how the forest changes.

Input Format

The first line contains n,mn, m, as described above.
The second line contains nn numbers, the initial weights of the nn nodes, each within 10310^3.
The next n1n - 1 lines each contain a pair u,vu, v, representing an edge. (It is guaranteed that initially it is a tree.)
The next mm lines contain mm operations:
First read an optopt, indicating the operation type.
When opt=1opt = 1, read ee, meaning to delete the ee-th input edge. (It is guaranteed that the ee-th edge exists.)
When opt=2opt = 2, read u,valu, val, meaning to change the weight of node uu to valval (val1000val \le 1000).
When opt=3opt = 3, read uu, meaning to query the sum of node weights in the tree that contains uu.

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 30%30\% of the testdata, 1n,m101 \leq n, m \leq 10 holds.
For 50%50\% of the testdata, 1n,m10001 \leq n, m \leq 1000 holds.
For the other 20%20\% of the testdata, only operations 22 and 33 exist.
For 100%100\% of the testdata, 1n,m1051 \leq n, m \leq 10^5, and 1v,val10001 \leq v, val \leq 1000 hold.

Translated by ChatGPT 5