You are given a tree with vertices numbered from to . Every vertex is colored either black or white.
is a binary tree. Initially, the root of is vertex .
Process the following queries.
1 : Change the root of to vertex .2 : Toggle the color of vertex . White becomes black, and black becomes white.3 : Let be the number of white vertices in the subtree rooted at vertex with respect to the current root. Let be the number of white vertices on the path from vertex to the current root. Both endpoints belong to the path. Print .It is guaranteed that is a binary tree regardless of which vertex is chosen as the root.
The input is given from Standard Input in the following format:
For every type 3 query, print the answer on its own line.
In the third type 3 query of the first case, vertices belong to the subtree, while vertices belong to the path to the root. The two white-vertex counts are and , so the answer is .
Each case is given in the following format:
If , vertex is black. If , vertex is white.
The -th edge connects vertices and .
Each has one of the forms 1 , 2 , and 3 .
3 query.| 3 | 43 | No additional constraints. |
The second case has only one vertex, so every type 3 query has answer .