#P1208H. Red Blue Tree
Red Blue Tree
No submission language available for this problem.
Description
You are given a tree of nodes. The tree is rooted at node , which is not considered as a leaf regardless of its degree.
Each leaf of the tree has one of the two colors: red or blue. Leaf node initially has color .
The color of each of the internal nodes (including the root) is determined as follows.
- Let be the number of blue immediate children, and be the number of red immediate children of a given vertex.
- Then the color of this vertex is blue if and only if , otherwise red.
Integer is a parameter that is same for all the nodes.
You need to handle the following types of queries:
- 1 v: print the color of node ;
- 2 v c: change the color of leaf to ( means red, means blue);
- 3 h: update the current value of to .
The first line of the input consists of two integers and (, ) — the number of nodes and the initial parameter .
Each of the next lines contains two integers and (), denoting that there is an edge between vertices and .
The next line consists of space separated integers — the initial array (). means that the color of node is red. means that the color of node is blue. means that the node is not a leaf.
The next line contains an integer (), the number of queries.
lines follow, each containing a query in one of the following queries:
- 1 v (): print the color of node ;
- 2 v c (, or ): change the color of leaf to ( means red, means blue). It is guaranteed that is a leaf;
- 3 h (): update the current value of to .
For each query of the first type, print if the color of vertex is red, and otherwise.
Input
The first line of the input consists of two integers and (, ) — the number of nodes and the initial parameter .
Each of the next lines contains two integers and (), denoting that there is an edge between vertices and .
The next line consists of space separated integers — the initial array (). means that the color of node is red. means that the color of node is blue. means that the node is not a leaf.
The next line contains an integer (), the number of queries.
lines follow, each containing a query in one of the following queries:
- 1 v (): print the color of node ;
- 2 v c (, or ): change the color of leaf to ( means red, means blue). It is guaranteed that is a leaf;
- 3 h (): update the current value of to .
Output
For each query of the first type, print if the color of vertex is red, and otherwise.
Samples
Note
(i) The initial tree
(ii) The tree after the 3rd query
(iii) The tree after the 7th query
