题库练习 LuoTianyi and XOR-Tree
← 上一题 下一题 →

A15918 | LuoTianyi and XOR-Tree

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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

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](https://en.wikipedia.org/wiki/Bitwise_operation#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 $n$ ( $2 \le n \le 10^5$ ) — the number of vertices in the tree.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ), the $i$ -th number represents the value in the $i$ -th vertex.

Next $n−1$ lines describe the edges of the tree. The $i$ -th line contains two integers $u_i$ and $v_i$ ( $1 \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.

输入输出样例

输入 #1
6
3 5 7 5 8 4
1 2
1 3
1 4
3 5
4 6
输出 #1
3
输入 #2
8
7 10 7 16 19 9 16 11
1 5
4 2
6 5
5 2
7 2
2 3
3 8
输出 #2
3
输入 #3
4
1 2 1 2
1 2
2 3
4 3
输出 #3
0
输入 #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
输出 #4
2
C++ 编辑器
输入
输出