PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000100. Cây tô màu (The Tree)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cây tô màu (The Tree)

The Tree

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a rooted tree with nn vertices numbered 11 through nn, rooted at vertex 11. Initially, every vertex is white. Each vertex is either white or black. Process the following qq operations in order:

  • 1 v: If vertex vv is white, paint it black and stop. If vv is black, recursively apply the same operation to every direct child of vv. Thus the operation may propagate along several branches; in each branch it stops at the first white vertex, or at the end of the branch.
  • 2 v: Paint the entire subtree rooted at vv, including vv, white.
  • 3 v: Report the current color of vertex vv.

The subtree of vv consists of vv and all of its descendants with root 11.

Input

  • The first line contains integers n,qn,q.
  • The next line contains n−1n-1 integers p2,p3,…,pnp_2,p_3,\ldots,p_n, where pip_i is the parent of vertex ii.
  • Each of the next qq lines contains two integers t v describing an operation.

Output

For each type-3 operation print black if the vertex is black, or white otherwise, on its own line.

Subtasks

  • Subtask 1 (10 points): 2≤n≤602\le n\le60, 1≤q≤1501\le q\le150; 1≤pi<i1\le p_i<i; 1≤t≤31\le t\le3, 1≤v≤n1\le v\le n.
  • Subtask 2 (20 points): 2≤n≤1052\le n\le10^5, 1≤q≤1051\le q\le10^5; 1≤pi<i1\le p_i<i; only operations of types 1 and 3; 1≤v≤n1\le v\le n.
  • Subtask 3 (30 points): 2≤n≤120002\le n\le12000, 1≤q≤120001\le q\le12000; 1≤pi<i1\le p_i<i; 1≤t≤31\le t\le3, 1≤v≤n1\le v\le n.
  • Subtask 4 (40 points): 2≤n≤1052\le n\le10^5, 1≤q≤1051\le q\le10^5; 1≤pi<i1\le p_i<i; 1≤t≤31\le t\le3, 1≤v≤n1\le v\le n.

Examples

Input

8 10
1 2 1 2 5 4 5
1 2
3 2
3 1
1 1
1 1
3 5
3 7
3 4
2 2
3 5

Output

black
white
black
white
black
white

Explanation

Operation 1 2 paints vertex 2 black because it was white. The next two queries check vertices 2 (black) and 1 (white). The first 1 1 paints the root black; the next 1 1 finds that the root is already black and recursively applies the operation to its children. Subsequent queries return black, white, and black. Finally, 2 2 makes the whole subtree of vertex 2 white; vertex 5 is white again.