Under construction

Still being built. Things may change

Vertices connected by the same color

Time limit2sMemory limit512 MB

Summary
Process color flip and reachability queries on a tree where two vertices are connected if every vertex on their path has the same color.
Level

Hard8 of 10

Topics
Tree, Union-find, DFS, Implementation
Solved
No attempts yet

Problem

You are given a tree with NN vertices. A tree is a connected undirected graph with no cycle. The vertices are numbered 1 to NN and the edges are numbered 1 to N−1N-1. Every vertex is black at the start.

Two vertices uu and vv are connected when every vertex on the path from uu to vv has the same color. The path from uu to uu is a single vertex, so uu is always connected to itself.

Write a program that processes the following two queries.

  • 1 i: change the color of vertex ii. Black becomes white, white becomes black.
  • 2 u: count the vertices vv that are connected to uu. Count uu itself as well.

Input

The first line contains the number of vertices NN. (2≤N≤1000002 \le N \le 100000)

Each of the next N−1N-1 lines contains the numbers uu and vv of the two vertices joined by an edge. (1≤u,v≤N1 \le u, v \le N, u≠vu \ne v) The given edges form a tree.

The next line contains the number of queries MM. (1≤M≤1000001 \le M \le 100000)

Each of the next MM lines contains one query. A query is either 1 i or 2 u, with 1≤i,u≤N1 \le i, u \le N.

Output

For each query of type 2, print the answer on its own line, in the order the queries are given.

Examples2

  1. Example 1

    Input
    5
    1 2
    1 3
    1 4
    1 5
    3
    2 1
    1 1
    2 1
    
    Expected output
    5
    1
    
  2. Example 2

    Input
    7
    1 2
    1 3
    2 4
    2 5
    3 6
    3 7
    4
    2 1
    1 1
    2 2
    2 3
    
    Expected output
    7
    3
    3