#P1208H. Red Blue Tree

    ID: 4914 Type: RemoteJudge 5000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>data structuresimplementationtrees*3500

Red Blue Tree

No submission language available for this problem.

Description

You are given a tree of nn nodes. The tree is rooted at node 11, 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 vv initially has color svs_{v}.

The color of each of the internal nodes (including the root) is determined as follows.

  • Let bb be the number of blue immediate children, and rr be the number of red immediate children of a given vertex.
  • Then the color of this vertex is blue if and only if brkb - r \ge k, otherwise red.

Integer kk 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 vv;
  • 2 v c: change the color of leaf vv to cc (c=0c = 0 means red, c=1c = 1 means blue);
  • 3 h: update the current value of kk to hh.

The first line of the input consists of two integers nn and kk (2n1052 \le n \le 10^{5}, nkn-n \le k \le n) — the number of nodes and the initial parameter kk.

Each of the next n1n - 1 lines contains two integers uu and vv (1u,vn1 \le u,v \le n), denoting that there is an edge between vertices uu and vv.

The next line consists of nn space separated integers — the initial array ss (1si1-1 \le s_i \le 1). si=0s_{i} = 0 means that the color of node ii is red. si=1s_{i} = 1 means that the color of node ii is blue. si=1s_{i} = -1 means that the node ii is not a leaf.

The next line contains an integer qq (1q1051 \le q \le 10^5), the number of queries.

qq lines follow, each containing a query in one of the following queries:

  • 1 v (1vn1 \le v \le n): print the color of node vv;
  • 2 v c (1vn1 \le v \le n, c=0c = 0 or c=1c = 1): change the color of leaf vv to cc (c=0c = 0 means red, c=1c = 1 means blue). It is guaranteed that vv is a leaf;
  • 3 h (nhn-n \le h \le n): update the current value of kk to hh.

For each query of the first type, print 00 if the color of vertex vv is red, and 11 otherwise.

Input

The first line of the input consists of two integers nn and kk (2n1052 \le n \le 10^{5}, nkn-n \le k \le n) — the number of nodes and the initial parameter kk.

Each of the next n1n - 1 lines contains two integers uu and vv (1u,vn1 \le u,v \le n), denoting that there is an edge between vertices uu and vv.

The next line consists of nn space separated integers — the initial array ss (1si1-1 \le s_i \le 1). si=0s_{i} = 0 means that the color of node ii is red. si=1s_{i} = 1 means that the color of node ii is blue. si=1s_{i} = -1 means that the node ii is not a leaf.

The next line contains an integer qq (1q1051 \le q \le 10^5), the number of queries.

qq lines follow, each containing a query in one of the following queries:

  • 1 v (1vn1 \le v \le n): print the color of node vv;
  • 2 v c (1vn1 \le v \le n, c=0c = 0 or c=1c = 1): change the color of leaf vv to cc (c=0c = 0 means red, c=1c = 1 means blue). It is guaranteed that vv is a leaf;
  • 3 h (nhn-n \le h \le n): update the current value of kk to hh.

Output

For each query of the first type, print 00 if the color of vertex vv is red, and 11 otherwise.

Samples

Sample Input 1

5 2
1 2
1 3
2 4
2 5
-1 -1 0 1 0
9
1 1
1 2
3 -2
1 1
1 2
3 1
2 5 1
1 1
1 2

Sample Output 1

0
0
1
1
0
1

Note

Figures:

(i) The initial tree

(ii) The tree after the 3rd query

(iii) The tree after the 7th query