#P7310. [COCI 2018/2019 #2] Deblo
[COCI 2018/2019 #2] Deblo
Description
Given a tree with nodes, where each node has a weight. The value of a path is defined as the XOR of the weights of all nodes on that path.
Your task is to compute the sum of the values of all paths.
Input Format
The first line contains a positive integer , representing the number of nodes in the tree.
The second line contains integers separated by spaces, where the -th integer represents the weight of node .
The next lines each contain two integers , indicating that there is an edge between and .
Output Format
Output the sum of the values of all paths.
3
1 2 3
1 2
2 3
10
5
2 3 4 2 1
1 2
1 3
3 4
3 5
64
6
5 4 1 3 3 3
3 1
3 5
4 3
4 2
2 6
85
Hint
Explanation for Sample 1
The value of path is .
The value of path is .
The value of path is .
The value of path is .
The value of path is .
The value of path is .
The sum of the values of all paths is .
Constraints
For of the testdata, .
For of the testdata, .
For the other of the testdata, for every node , there is an edge between node and node .
For of the testdata, , and .
Notes
This problem uses the original COCI scoring. The full score is .
Translated from COCI2018-2019 CONTEST #2 T3 Deblo.
Translated by ChatGPT 5
京公网安备 11011102002149号