Codeforces Round 200 (Div. 1)
D
Water Tree
Codeforces
2100
原题
← CE →
翻译中…

Mad scientist Mike has constructed a rooted tree, which consists of $*n*$ vertices. Each vertex is a reservoir which can be either empty or filled with water.

翻译中…

The vertices of the tree are numbered from 1 to $*n*$ with the root at vertex 1. For each vertex, the reservoirs of its children are located below the reservoir of this vertex, and the vertex is connected with each of the children by a pipe through which water can flow downwards.

翻译中…

Mike wants to do the following operations with the tree:

翻译中…
  1. Fill vertex $*v*$ with water. Then $*v*$ and all its children are filled with water.
  2. Empty vertex $*v*$. Then $*v*$ and all its ancestors are emptied.
  3. Determine whether vertex $*v*$ is filled with water at the moment.
翻译中…

Initially all vertices of the tree are empty.

翻译中…

Mike has already compiled a full list of operations that he wants to perform in order. Before experimenting with the tree Mike decided to run the list through a simulation. Help Mike determine what results will he get after performing all the operations.

翻译中…

Input

翻译中…

The first line of the input contains an integer $*n*$ ($1 ≤ *n* ≤ 500000$) — the number of vertices in the tree. Each of the following $*n* - 1$ lines contains two space-separated numbers $*a*_{*i*}$, $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$, $*a*_{*i*} ≠ *b*_{*i*}$) — the edges of the tree.

翻译中…

The next line contains a number $*q*$ ($1 ≤ *q* ≤ 500000$) — the number of operations to perform. Each of the following $*q*$ lines contains two space-separated numbers $*c*_{*i*}$ ($1 ≤ *c*_{*i*} ≤ 3$), $*v*_{*i*}$ ($1 ≤ *v*_{*i*} ≤ *n*$), where $*c*_{*i*}$ is the operation type (according to the numbering given in the statement), and $*v*_{*i*}$ is the vertex on which the operation is performed.

翻译中…

It is guaranteed that the given graph is a tree.

翻译中…

Output

翻译中…

For each type 3 operation print 1 on a separate line if the vertex is full, and 0 if the vertex is empty. Print the answers to queries in the order in which the queries are given in the input.

翻译中…

样例

Input #1
5
1 2
5 1
2 3
4 2
12
1 1
2 3
3 1
3 2
3 3
3 4
1 2
2 4
3 1
3 3
3 4
3 5
Output #1
0
0
0
1
0
1
0
1
InputCopy OutputCopy
题目信息
题号
343D
时间限制
4 s
内存限制
256 MB
标签
数据结构
DFS 及类似
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。