#P1626E. Black and White Tree

    ID: 102 Type: RemoteJudge 4000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>dfs and similargreedytrees*2400

Black and White Tree

No submission language available for this problem.

Description

You are given a tree consisting of nn vertices. Some of the vertices (at least two) are black, all the other vertices are white.

You place a chip on one of the vertices of the tree, and then perform the following operations:

  • let the current vertex where the chip is located is xx. You choose a black vertex yy, and then move the chip along the first edge on the simple path from xx to yy.

You are not allowed to choose the same black vertex yy in two operations in a row (i. e., for every two consecutive operations, the chosen black vertex should be different).

You end your operations when the chip moves to the black vertex (if it is initially placed in a black vertex, you don't perform the operations at all), or when the number of performed operations exceeds 100500100^{500}.

For every vertex ii, you have to determine if there exists a (possibly empty) sequence of operations that moves the chip to some black vertex, if the chip is initially placed on the vertex ii.

The first line contains one integer nn (3n31053 \le n \le 3 \cdot 10^5) — the number of vertices in the tree.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (0ci10 \le c_i \le 1), where ci=0c_i = 0 means that the ii-th vertex is white, and ci=1c_i = 1 means that the ii-th vertex is black. At least two values of cic_i are equal to 11.

Then n1n-1 lines follow, each of them contains two integers uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n; uiviu_i \ne v_i) — the endpoints of some edge. These edges form a tree.

Print nn integers. The ii-th integer should be equal to 11 if there exists a (possibly empty) sequence of operations that moves the chip to some black vertex if it is placed on the vertex ii, and 00 if no such sequence of operations exists.

Input

The first line contains one integer nn (3n31053 \le n \le 3 \cdot 10^5) — the number of vertices in the tree.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (0ci10 \le c_i \le 1), where ci=0c_i = 0 means that the ii-th vertex is white, and ci=1c_i = 1 means that the ii-th vertex is black. At least two values of cic_i are equal to 11.

Then n1n-1 lines follow, each of them contains two integers uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n; uiviu_i \ne v_i) — the endpoints of some edge. These edges form a tree.

Output

Print nn integers. The ii-th integer should be equal to 11 if there exists a (possibly empty) sequence of operations that moves the chip to some black vertex if it is placed on the vertex ii, and 00 if no such sequence of operations exists.

Samples

Sample Input 1

8
0 1 0 0 0 0 1 0
8 6
2 5
7 8
6 5
4 5
6 1
7 3

Sample Output 1

0 1 1 1 1 0 1 1