Under construction

Still being built. Things may change

Tree

Time limit2sMemory limit512 MB

Summary
Given a rooted tree, process a mix of edge deletions and connectivity queries in order, answering YES or NO for each query.
Level

Medium6 of 10

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

Problem

A tree T is built from vertices and edges. A vertex is drawn as a circle and an edge is a line joining two vertices. The vertex at the very top is the root, and there is only one root. The N vertices are numbered 1 to N, and the root is always vertex 1.

A path joining vertices v and w is an ordered list of vertices (v0,v1,…,vm)(v_0, v_1, \dots, v_m) with v0=vv_0 = v and vm=wv_m = w, where viv_i and vi+1v_{i+1} are joined by an edge. In a tree exactly one path exists between any two vertices. In Figure 1 the only path between vertex 3 and vertex 11 is (3, 4, 1, 7, 11).

Figure 1

Let P be the unique path from vertex v to the root. The vertex joined to v by an edge that lies on P is the parent of v. In Figure 1 the parent of 4, 7 and 9 is 1, and the parent of 2 and 11 is 7.

Removing one edge can cut the path between vertex pairs other than its two endpoints. In Figure 1, once the edge between 7 and 11 is removed, no path joins 8 and 5.

You are given the tree, and then edge removals and queries mixed in an arbitrary order. Carry out the operations in the given order and print the answer to each query.

Input

The first line contains the number of vertices N and the number of queries Q (1≤N,Q≤2000001 \le N, Q \le 200000).

The i-th of the next N-1 lines contains the parent a of vertex i+1 (1≤a≤N1 \le a \le N).

The next (N-1)+Q lines contain the operations. N-1 of them have form (1) and Q of them have form (2).

(1) Two integers x and b (x=0x = 0, 2≤b≤N2 \le b \le N). This removes the edge joining b and the parent of b. The value b differs on every such line.

(2) Three integers x, c and d (x=1x = 1, 1≤c,d≤N1 \le c, d \le N). This asks whether a path joining c and d exists.

Output

Print the answers in the given order, one query per line. Print YES if a path exists and NO otherwise.

Examples6

  1. Example 1

    Input
    3 3
    1
    1
    1 2 3
    0 3
    1 2 3
    1 1 2
    0 2
    
    Expected output
    YES
    NO
    YES
    
  2. Example 2

    Input
    11 5
    7
    4
    1
    9
    11
    1
    11
    1
    3
    7
    0 11
    1 8 5
    1 3 9
    0 10
    0 9
    0 7
    1 2 7
    0 5
    1 1 10
    0 8
    0 6
    0 2
    1 1 3
    0 3
    0 4
    
    Expected output
    NO
    YES
    YES
    NO
    YES
    
  3. Example 3

    Input
    1 1
    1 1 1
    
    Expected output
    YES
    
  4. Example 4

    Input
    2 3
    1
    1 1 2
    0 2
    1 1 2
    1 2 2
    
    Expected output
    YES
    NO
    YES
    
  5. Example 5

    Input
    6 6
    1
    2
    3
    4
    5
    1 1 6
    0 4
    1 1 6
    1 5 6
    0 6
    1 5 6
    0 2
    1 1 2
    0 3
    0 5
    1 1 1
    
    Expected output
    YES
    NO
    YES
    NO
    NO
    YES
    
  6. Example 6

    Input
    6 4
    1
    1
    1
    1
    1
    1 2 3
    0 3
    1 2 3
    0 2
    0 4
    1 5 6
    0 5
    0 6
    1 1 4
    
    Expected output
    YES
    NO
    YES
    NO