Queries on tree 2 - MarisaOJ: Marisa Online Judge

Queries on tree 2

Time limit: 500 ms
Memory limit: 256 MB
Given a tree with n vertices and rooted at 1. Each vertex has an initial value, and initially, all these values are 0. There are q queries of two types: - 1u: Find the sum of values of vertices in the subtree rooted at u. - 2u: Find the value at vertex u. - 3uvx: Increase the values of vertices on the simple path from u to v by x. Answer the queries of types 1 and 2. ### Input - The first line contains two integers n and q. - The next n−1 lines each contain two integers u and v, indicating an edge between u and v. - The next q lines each contain a query in the specified format. ### Output - Print an integer as the answer for each query of types 1 and 2. ### Constraints - 1≤n,q≤2×105. - 1≤u,v≤n. - 0≤|x|≤106. ### Example Input: 51012232425324225151215112234442312 Output: 00404208