Processing math: 100%
Queries on tree - MarisaOJ: Marisa Online Judge

Queries on tree

Time limit: 500 ms
Memory limit: 256 MB
Given a tree with n vertices rooted at 1, where each vertex initially has a value of 0. There are q queries, each belonging to one of the following two types: - 1ux: Increase the values of vertices in the subtree rooted at u by x. - 2ux: Increase the value of vertex u by x. - 3uv: Find the sum of values of vertices on the simple path from u to v. Answer the queries of type 3. ### Input - The first line contains two integers n and q. - The next n−1 lines each contain two integers u and v, indicating there is an edge between u and v. - The next q lines each contain a query in the specified format. ### Output - Print an integer, the answer for each query of type 3. ### Constraints - 1≤n,q≤2×105. - 1≤u,v≤n. - 0≤|x|≤106. ### Example Input: 5101223242514-125-4345325322342255312133321 Output: -5-40-100