#include<iostream> #define maxn 100010 #define maxm 2000010 #define ll long long usingnamespacestd;
int n, a[maxn];
structEdge { int to, next; } e[maxn * 2]; int c1, head[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; e[c1].next = head[u]; head[u] = c1++; }
int f[maxn][2]; ll ans; voiddfs(int u, int fa, int o){ int d = a[u] >> o & 1; f[u][d] = 1; f[u][d ^ 1] = 0; for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (v == fa) continue; dfs(v, u, o); for (int k = 0; k < 2; ++k) ans += (1ll << o) * f[u][k] * f[v][k ^ 1]; for (int k = 0; k < 2; ++k) f[u][k] += f[v][k ^ d]; } }
intmain(){ fill(head, head + maxn, -1); ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], ans += a[i]; for (int i = 1; i < n; ++i) { int x, y; cin >> x >> y; add_edge(x, y); add_edge(y, x); } for (int i = 0; i <= 20; ++i) dfs(1, 0, i); cout << ans << "\n"; return0; }