Under construction

Still being built. Things may change

Bitset Master

Time limit6sMemory limit512 MB

Summary
Each vertex starts with its own set, edge operations merge the sets at both endpoints, and queries count how many sets contain a given vertex.
Level

Hard9 of 10

Topics
Tree, Union-find, Divide and conquer
Solved
No attempts yet

Problem

It is well known in China that O(n2)O(n^2) algorithms can pass a problem with n=106n = 10^6 easily.

You are given a tree with nn vertices and n−1n - 1 edges (u1,v1),(u2,v2),…,(un−1,vn−1)(u_1, v_1), (u_2, v_2), \ldots, (u_{n-1}, v_{n-1}). Each vertex uu has a set SuS_u. Initially Su={u}S_u = \{u\}.

There are two types of operations.

  • "1 u": output the number of sets SvS_v (1≤v≤n1 \le v \le n) that contain uu.
  • "2 p": take the sets SupS_{u_p} and SvpS_{v_p}, where (up,vp)(u_p, v_p) is the pp-th edge, and assign Sup∪SvpS_{u_p} \cup S_{v_p} to both of them.

You need to perform mm operations. Output the answer for each operation of the first kind.

The time limit is 6000 ms and the memory limit is 512 MB.

Input

The first line contains two integers nn and mm (2≤n≤2×1052 \le n \le 2 \times 10^5, 1≤m≤6×1051 \le m \le 6 \times 10^5).

Each of the following n−1n - 1 lines contains two integers uiu_i and viv_i describing an edge (1≤ui,vi≤n1 \le u_i, v_i \le n).

Each of the following mm lines contains two integers tt and ww describing an operation (1≤t≤21 \le t \le 2, 1≤w≤n+1−t1 \le w \le n + 1 - t).

Output

For each operation of the first kind, output an integer on a separate line.

Examples1

  1. Example 1

    Input
    5 11
    1 2
    1 3
    1 4
    1 5
    2 4
    2 3
    2 2
    2 1
    1 1
    1 2
    1 3
    2 2
    2 3
    1 4
    1 5
    
    Expected output
    5
    2
    3
    4
    5