Xorability

Consider a tree with nn nodes numbered from 1 to nn, rooted at 1. Each node ii has a natural label i\ell_i. Given two nodes uu and vv, define X(u,v)X(u, v) as the exclusive or (^ in C++) of all the i\ell_i in the path from uu to vv.

Let LL be the set of leaves of the tree. Please compute vLX(1,v)\sum_{v \in L} X(1, v).

Input

Input consists of several trees, each with the number of nodes nn, followed by 1,,n\ell_1, \dots, \ell_n, followed by n1n - 1 pairs of nodes describing the edges of the tree. Assume 2n1052 \le n \le 10^5, and 0li1090 \le l_i \le 10^9.

Output

For each tree, print the required sum.

Problem information

Author: Ángel García

Generation: 2026-01-25T11:12:53.826Z

© Jutge.org, 2006–2026.
https://jutge.org