You are given a tree with vertices numbered . Initially, vertex has value .
Process queries in order. It is guaranteed that after each query, the graph is a tree.
0 : remove the existing edge , and add the edge .The input is given in the following format.
For each query of type 2, print the required sum of vertex values on a separate line.
In the first query, with respect to edge , the component on the side of vertex contains vertices , so the sum is .
1 : update .2 : for the current edge , regard as the parent side of . Output the sum of values of all vertices in the connected component containing after removing this edge.denote the -th edge of the initial tree. Each query is given in one of the three formats described in the statement.
0, the removed edge currently exists.0, the graph is a tree.1, and .2, the edge currently exists.Then the value of vertex becomes , so the answer to the second query is .
The remaining answers are computed in the same way on the current tree.