CF343D.Water Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mad scientist Mike has constructed a rooted tree, which consists of nn 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 nn 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 vv with water. Then vv and all its children are filled with water.
  2. Empty vertex vv . Then vv and all its ancestors are emptied.
  3. Determine whether vertex vv 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.

输入格式

The first line of the input contains an integer nn ( 1<=n<=5000001<=n<=500000 ) — the number of vertices in the tree. Each of the following n1n-1 lines contains two space-separated numbers aia_{i} , bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n , aibia_{i}≠b_{i} ) — the edges of the tree.

The next line contains a number qq ( 1<=q<=5000001<=q<=500000 ) — the number of operations to perform. Each of the following qq lines contains two space-separated numbers cic_{i} ( 1<=ci<=31<=c_{i}<=3 ), viv_{i} ( 1<=vi<=n1<=v_{i}<=n ), where cic_{i} is the operation type (according to the numbering given in the statement), and viv_{i} is the vertex on which the operation is performed.

It is guaranteed that the given graph is a tree.

输出格式

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.

输入输出样例

  • 输入#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
    

    输出#1

    0
    0
    0
    1
    0
    1
    0
    1
    
首页