#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse2,avx")
using namespace std;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 1e5 + 3, K = 21;
long long n, a[N], pref[N], f[N][K], ans, magic;
vector<long long> q[N];
vector<long long>* st[N];
void add(long long x, long long y) {
  for (long long i = 0; i < K; i++) {
    if (pref[y] & (1 << i)) {
      f[x][i]++;
    }
  }
  st[x]->push_back(y);
}
void upd(long long x, long long y) {
  long long tmp = (pref[y] ^ a[x]);
  for (long long i = 0; i < K; i++) {
    long long sgn = 1;
    if (tmp & (1 << i)) {
      sgn = -1;
    }
    ans += sgn * f[x][i] * (1 << i);
  }
  ans += (long long)st[x]->size() * tmp;
}
void prep(long long v, long long p) {
  pref[v] = (pref[p] ^ a[v]);
  for (auto i : q[v]) {
    if (i == p) {
      continue;
    }
    prep(i, v);
  }
}
void dfs(long long v, long long p) {
  long long mx = -1, big = -1;
  for (auto i : q[v]) {
    if (i == p) {
      continue;
    }
    dfs(i, v);
    if ((long long)st[i]->size() > mx) {
      mx = st[i]->size();
      big = i;
    }
  }
  if (big == -1) {
    st[v] = new vector<long long>();
  } else {
    st[v] = st[big];
    for (long long i = 0; i < K; i++) {
      f[v][i] = f[big][i];
    }
  }
  for (auto i : q[v]) {
    if (i == p || i == big) {
      continue;
    }
    for (auto j : *st[i]) {
      upd(v, j);
    }
    for (auto j : *st[i]) {
      add(v, j);
    }
  }
  upd(v, v);
  add(v, v);
}
void solve(long long tc) {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    magic += a[i];
  }
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    q[x].push_back(y);
    q[y].push_back(x);
  }
  prep(1, 1);
  dfs(1, 1);
  cout << ans + magic;
}
signed main() {
  long long tc = 1;
  for (long long i = 0; i < tc; i++) {
    solve(i);
  }
}
