#include <bits/stdc++.h>
using namespace std;
int v[100010], blocked[100010], sz[100010];
vector<int> g[100010];
long long ans = 0LL, freq[22][2];
void build_sz(int at, int pai) {
  sz[at] = 1;
  for (int x : g[at])
    if (x != pai && !blocked[x]) build_sz(x, at), sz[at] += sz[x];
}
int find_centroid(int at, int pai, int tam) {
  for (int x : g[at])
    if (x != pai && !blocked[x] && sz[x] > tam / 2)
      return find_centroid(x, at, tam);
  return at;
}
void dfs_cont(int at, int pai, int val) {
  val ^= v[at];
  for (int i = 0; i < 22; i++)
    ans += (freq[i][((val >> i) & 1) ^ 1]) * (1 << i);
  for (int x : g[at])
    if (x != pai && !blocked[x]) dfs_cont(x, at, val);
}
void dfs_add(int at, int pai, int val) {
  val ^= v[at];
  for (int i = 0; i < 22; i++) freq[i][(val >> i) & 1]++;
  for (int x : g[at])
    if (x != pai && !blocked[x]) dfs_add(x, at, val);
}
void decompose(int at) {
  build_sz(at, at);
  at = find_centroid(at, at, sz[at]);
  for (int i = 0; i < 22; i++) freq[i][(v[at] >> i) & 1]++;
  blocked[at] = 1;
  for (int x : g[at]) {
    if (!blocked[x]) dfs_cont(x, x, 0), dfs_add(x, x, v[at]);
  }
  memset(freq, 0, sizeof freq);
  for (int x : g[at])
    if (!blocked[x]) decompose(x);
}
int main() {
  int i, n, a, b;
  scanf("%d", &n);
  ans = 0;
  for (i = 1; i <= n; i++) scanf("%d", &v[i]), ans += v[i];
  for (i = 0; i < n - 1; i++)
    scanf("%d%d", &a, &b), g[a].push_back(b), g[b].push_back(a);
  decompose(1);
  printf("%lld\n", ans);
}
