Radius - MarisaOJ: Marisa Online Judge

Radius

Time limit: 2000 ms
Memory limit: 256 MB
The problem involves a tree with $n$ vertices, where each vertex $i$ has a value $A_i$. There are $q$ queries of two types: - `1 u k`: Calculate the sum of values of vertices with a shortest path to vertex u not exceeding $k$. - `2 u v`: Change the value at vertex $u$ to $v$. ### Input - The first line contains two integers $n$ and $q$. - The second line contains $n$ integers $A_i$, representing the values at each vertex. - The next $q$ lines contain queries in the specified format. ### Output - For each query of type 1, output an integer representing the answer. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le A_i,x \le 10^4$. - $1 \le u,k \le n$. ### Sample test Input ``` 7 7 8 3 6 5 6 10 6 1 2 2 3 1 4 2 5 2 6 3 7 2 7 9 2 2 2 2 4 10 1 2 2 2 7 10 1 7 1 1 2 3 ``` Output: ``` 51 16 52 ```