301816: CF343D. Water Tree
Memory Limit:256 MB
Time Limit:4 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Water Tree
题意翻译
- 给出一棵以 $1$ 为根节点的 $n$ 个节点的有根树。每个点有一个权值,初始为 $0$。 - $m$ 次操作。操作有 $3$ 种: 1. 将点 $u$ 和其子树上的所有节点的权值改为 $1$。 2. 将点 $u$ 到 $1$ 的路径上的所有节点的权值改为 $0$。 3. 询问点 $u$ 的权值。 - $1\le n,m\le 5\times 10^5$。题目描述
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.输入输出格式
输入格式
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.
输出格式
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