CF1824C.LuoTianyi and XOR-Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

输入输出样例

  • 输入#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 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.

首页