P8238 [AGM 2022 Qualification Round] Shelter.
Description
Country U has $n$ buildings. The first building is the shelter, and they are connected by $n-1$ roads. Each building has a certain number of refugees. Initially, the number of refugees in building $i$ is $a_i$.
During the war, $q$ events occur. There are two types of events:
* `1 x y`: The number of refugees in building $x$ becomes $y$.
* `2 x`: The road that is closest to the shelter on the path from building $x$ to the shelter changes its state: if it was open, it becomes blocked; otherwise, it becomes open. At the beginning, every road is open. It is guaranteed that $x \neq 1$.
After each event, you need to output how many refugees can reach the shelter by following open roads.
Input Format
The first line contains two positive integers $n, q$.
The next $n-1$ lines each contain two integers $u, v$, indicating that there is an edge connecting $u$ and $v$.
The next line contains $n$ integers $a_i$.
The following $q$ lines each contain two or three integers, representing one event.
Output Format
Output $q$ lines. Each line contains one number, representing the answer.
Explanation/Hint
#### Constraints
For $100\%$ of the testdata, it is guaranteed that $1 \leq n, q \leq 10^5$ and $0 \leq a_i, y \leq 10^9$.
#### Notes
Translated from [AGM 2022 Qualification Round J Shelters](https://judge.agm-contest.com/public/problems/6/text)。
Translated by ChatGPT 5