Xorability

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

Let L be the set of leaves of the tree. Please compute ∑_(v ∈ L)X(1, v).

Input

Input consists of several trees, each with the number of nodes n,
followed by ℓ₁, …, ℓ_(n), followed by n − 1 pairs of nodes describing
the edges of the tree. Assume 2 ≤ n ≤ 10⁵, and 0 ≤ l_(i) ≤ 10⁹.

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
