#SRD0000100. Cây tô màu (The Tree)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 vertices numbered through , rooted at vertex . Initially, every vertex is white. Each vertex is either white or black. Process the following operations in order:
1 v: If vertex is white, paint it black and stop. If is black, recursively apply the same operation to every direct child of . 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 , including , white.3 v: Report the current color of vertex .
The subtree of consists of and all of its descendants with root .
Input
- The first line contains integers .
- The next line contains integers , where is the parent of vertex .
- Each of the next lines contains two integers
t vdescribing 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): , ; ; , .
- Subtask 2 (20 points): , ; ; only operations of types 1 and 3; .
- Subtask 3 (30 points): , ; ; , .
- Subtask 4 (40 points): , ; ; , .
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.