#SGM0000085. Cây nước (Water Tree)
Cây nước (Water Tree)
Water Tree
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem
Initially every vertex is empty. There are three operations:
- Fill a vertex and every vertex in its subtree.
- Empty a vertex and every ancestor of that vertex.
- Query whether a vertex is currently full.
The tree is rooted at vertex 1.
Input
The first line contains . The next lines contain the tree edges. The next line contains . Each of the next lines contains type v, where :
1 v: fill the subtree of .2 v: empty and all its ancestors.3 v: query the state of .
Output
For every operation of type 3, print 1 if vertex is full, otherwise print 0.
Subtasks
Subtask 1 (20%)
- The tree size and number of operations are at most 20.
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- The tree size and number of operations are at most 2000.
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- .
Example
Input
1
6
2 1
1 1
1 1
3 1
3 1
2 1
Output
1
1
Explanation
After the fill operations, vertex 1 is full, so both type-3 queries print 1. The final type-2 operation happens after those queries.