#P1824C. LuoTianyi and XOR-Tree

    ID: 8495 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>data structuresdfs and similardpdsugreedytrees*2500

LuoTianyi and XOR-Tree

No submission language available for this problem.

Description

LuoTianyi gives you a tree with values in its vertices, and the root of the tree is vertex 11.

In one operation, you can change the value in one vertex to any non-negative integer.

Now you need to find the minimum number of operations you need to perform to make each path from the root to leaf^{\dagger} has a bitwise XOR value of zero.

^{\dagger}A leaf in a rooted tree is a vertex that has exactly one neighbor and is not a root.

The first line contains a single integer nn (2n1052 \le n \le 10^5) — the number of vertices in the tree.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9), the ii-th number represents the value in the ii-th vertex.

Next n1n−1 lines describe the edges of the tree. The ii-th line contains two integers uiu_i and viv_i (1ui,vin,uivi1 \le u_i,v_i \le n, u_i \neq v_i) — the vertices connected by an edge of the tree. It's guaranteed that the given edges form a tree.

Print a single integer — the minimum number of operations.

Input

The first line contains a single integer nn (2n1052 \le n \le 10^5) — the number of vertices in the tree.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9), the ii-th number represents the value in the ii-th vertex.

Next n1n−1 lines describe the edges of the tree. The ii-th line contains two integers uiu_i and viv_i (1ui,vin,uivi1 \le u_i,v_i \le n, u_i \neq v_i) — the vertices connected by an edge of the tree. It's guaranteed that the given edges form a tree.

Output

Print a single integer — the minimum number of operations.

Sample Input 1

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

Sample Output 1

3

Sample Input 2

8
7 10 7 16 19 9 16 11
1 5
4 2
6 5
5 2
7 2
2 3
3 8

Sample Output 2

3

Sample Input 3

4
1 2 1 2
1 2
2 3
4 3

Sample Output 3

0

Sample Input 4

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

Sample Output 4

2

Note

The tree in the first example:

If we change the value in the vertex 22 to 33, the value in the vertex 55 to 44, and the value in the vertex 66 to 66, then the tree will be ok.

The bitwise XOR from the root to the leaf 22 will be 33=03 \oplus 3=0.

The bitwise XOR from the root to the leaf 55 will be 473=04 \oplus 7 \oplus 3=0.

The bitwise XOR from the root to the leaf 66 will be 653=06 \oplus 5 \oplus 3=0.

The tree in the second example:

If we change the value in the vertex 22 to 44, the value in the vertex 33 to 2727, and the value in the vertex 66 to 2020, then the tree will be ok.

The bitwise XOR from the root to the leaf 66 will be 20197=020 \oplus 19 \oplus 7=0.

The bitwise XOR from the root to the leaf 88 will be 11274197=011 \oplus 27 \oplus 4 \oplus 19 \oplus 7=0.

The bitwise XOR from the root to the leaf 44 will be 164197=016 \oplus 4 \oplus 19 \oplus 7=0.

The bitwise XOR from the root to the leaf 77 will be 164197=016 \oplus 4 \oplus 19 \oplus 7=0.

In the third example, the only leaf is the vertex 44 and the bitwise XOR on the path to it is 1212=01 \oplus 2 \oplus 1 \oplus 2 = 0, so we don't need to change values.

In the fourth example, we can change the value in the vertex 11 to 55, and the value in the vertex 44 to 00.

Here \oplus denotes the bitwise XOR operation.