CF1824C.LuoTianyi and XOR-Tree
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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† has a bitwise XOR value of zero.
†A leaf in a rooted tree is a vertex that has exactly one neighbor and is not a root.
洛天依给你一棵顶点带权的树,树的根节点为顶点 1。
在一次操作中,你可以将任意一个顶点的权值修改为任意非负整数。
现在你需要求出:为使从根节点到每个叶节点†的每条路径的按位异或(XOR)值均为零,所需的最少操作次数。
† 在有根树中,叶节点指恰好有一个邻接顶点且不是根节点的顶点。
输入格式
The first line contains a single integer n (2≤n≤105) — the number of vertices in the tree.
The second line contains n integers a1,a2,…,an (1≤ai≤109), 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 ui and vi (1≤ui,vi≤n,ui=vi) — the vertices connected by an edge of the tree. It's guaranteed that the given edges form a tree.
第一行包含一个整数 n(2≤n≤105)—— 树中顶点的数量。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),其中第 i 个数表示第 i 个顶点上的值。
接下来的 n−1 行描述树的边。第 i 行包含两个整数 ui 和 vi(1≤ui,vi≤n,ui=vi)—— 表示由一条树边相连的两个顶点。保证所给的边构成一棵树。
输出格式
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
说明/提示
The tree in the first example:

If we change the value in the vertex 2 to 3, the value in the vertex 5 to 4, and the value in the vertex 6 to 6, then the tree will be ok.
The bitwise XOR from the root to the leaf 2 will be 3⊕3=0.
The bitwise XOR from the root to the leaf 5 will be 4⊕7⊕3=0.
The bitwise XOR from the root to the leaf 6 will be 6⊕5⊕3=0.
The tree in the second example:

If we change the value in the vertex 2 to 4, the value in the vertex 3 to 27, and the value in the vertex 6 to 20, then the tree will be ok.
The bitwise XOR from the root to the leaf 6 will be 20⊕19⊕7=0.
The bitwise XOR from the root to the leaf 8 will be 11⊕27⊕4⊕19⊕7=0.
The bitwise XOR from the root to the leaf 4 will be 16⊕4⊕19⊕7=0.
The bitwise XOR from the root to the leaf 7 will be 16⊕4⊕19⊕7=0.
In the third example, the only leaf is the vertex 4 and the bitwise XOR on the path to it is 1⊕2⊕1⊕2=0, so we don't need to change values.
In the fourth example, we can change the value in the vertex 1 to 5, and the value in the vertex 4 to 0.
Here ⊕ denotes the bitwise XOR operation.
第一个示例中的树:

如果我们把顶点 2 的值改为 3,顶点 5 的值改为 4,顶点 6 的值改为 6,则该树即满足要求。
从根节点到叶子节点 2 的路径上所有节点值的按位异或(XOR)结果为 3⊕3=0。
从根节点到叶子节点 5 的路径上所有节点值的按位异或结果为 4⊕7⊕3=0。
从根节点到叶子节点 6 的路径上所有节点值的按位异或结果为 6⊕5⊕3=0。
第二个示例中的树:

如果我们把顶点 2 的值改为 4,顶点 3 的值改为 27,顶点 6 的值改为 20,则该树即满足要求。
从根节点到叶子节点 6 的路径上所有节点值的按位异或结果为 20⊕19⊕7=0。
从根节点到叶子节点 8 的路径上所有节点值的按位异或结果为 11⊕27⊕4⊕19⊕7=0。
从根节点到叶子节点 4 的路径上所有节点值的按位异或结果为 16⊕4⊕19⊕7=0。
从根节点到叶子节点 7 的路径上所有节点值的按位异或结果为 16⊕4⊕19⊕7=0。
在第三个示例中,唯一的叶子节点是顶点 4,而其路径上的按位异或值为 1⊕2⊕1⊕2=0,因此无需修改任何值。
在第四个示例中,我们可以将顶点 1 的值改为 5,并将顶点 4 的值改为 0。
其中 ⊕ 表示按位异或(bitwise XOR)运算。
输入解题思路,AI测评打分。不知道怎么写?