Subtree update - MarisaOJ: Marisa Online Judge

Subtree update

Time limit: 1000 ms
Memory limit: 256 MB
Suppose we have a tree with $n$ vertices, rooted at $1$. Initially, the value written on each vertex is $0$. We are provided with $q$ queries, which can be of two forms: - `1 u v` - This query increases the value on each vertex in the subtree rooted at vertex $u$ by the amount $v$. - `2 u` - This query seeks to find the value of vertex $u$. ### Input - The first line contains two integer $n,q$. - The next $n - 1$ lines, each containing two integers $u,v$, there is an edge between $u$ and $v$. - The next $q$ lines, each containing a query in one of the following two forms: + `1 u v` - Query type 1, indicating an increment of $v$ to each vertex in the subtree rooted at vertex $u$. + `2 u` - Query type 2, requesting the value assigned to vertex $u$. ### Output - For each query of type 2, output a single line containing the value assigned to the corresponding vertex. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le u \le n$. - $|v| \le 10^9$. ### Example Input: ``` 10 6 1 2 2 3 2 4 2 5 2 6 4 7 2 8 1 9 9 10 2 6 1 2 5 2 5 2 6 1 1 -5 2 1 ``` Output: ``` 0 5 5 -5 ```