#P8827. YYH Land Forest Guardians
YYH Land Forest Guardians
YYH Land Forest Guardians
In the magical land of YYH Land, the forest is maintained by Qingzheng Yu, a dedicated guardian. Initially, there is a tree with n nodes and n-1 edges. Each node i has a spiritual power value \(v_i\). The tree has a mysterious ability to undergo the following operations:
1 e
: The edge with index \(e\) suddenly disappears, splitting the tree into two separate trees.2 u val
: The spiritual power at node \(u\) is updated, so that \(v_u = val\).3 u
: Query the sum of the spiritual power values of the whole tree that contains node \(u\).
Your task is to simulate these operations and output the results of each query.
Input Explanation:
The first line contains two integers \(n\) and \(q\), the number of nodes and the number of operations.
The second line contains \(n\) integers \(v_1, v_2, \dots, v_n\), where \(v_i\) represents the initial spiritual power of node \(i\).
The next \(n-1\) lines each contain two integers \(u\) and \(v\) describing an edge connecting nodes \(u\) and \(v\). The edges are numbered from 1 to \(n-1\) in the order they are given.
The following \(q\) lines describe the operations in the format specified above.
Output Explanation:
For each operation of type 3, output one line containing the sum of the spiritual power values in the tree that contains node \(u\).
inputFormat
The first line contains two integers \(n\) (number of nodes) and \(q\) (number of operations).
The second line contains \(n\) integers: \(v_1, v_2, \dots, v_n\).
Then \(n-1\) lines follow, each with two integers \(u\) and \(v\) representing an edge between nodes \(u\) and \(v\).
After that, \(q\) lines follow, each describing an operation in one of the following forms:
1 e
, 2 u val
, or 3 u
.
outputFormat
For each query of type 3 u
, output a single integer representing the sum of the spiritual power values of the tree containing node \(u\>.
sample
5 5
1 2 3 4 5
1 2
1 3
3 4
3 5
3 3
2 3 10
3 3
1 2
3 3
15
22
19
</p>