#include <bits/stdc++.h>
using namespace std;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ' ';
  err(++it, args...);
}
const int N = (int)1e5 + 5;
const int maxN = (int)1e6 + 6;
const long long Mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long Inf = (long long)1e18;
vector<vector<int> > g;
int sub[N], len, k, n, dp[21][2], a[N];
bool vis[N];
void dfs(int s, int p = 0) {
  sub[s] = 1;
  ++len;
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    dfs(i, s);
    sub[s] += sub[i];
  }
}
int Centroid(int s, int p) {
  for (int i : g[s]) {
    if (i != p and vis[i] == 0 and sub[i] > len / 2) return Centroid(i, s);
  }
  return s;
}
void upd(int d) {
  for (int i = 0; i < 21; ++i) {
    dp[i][(bool)(d & (1 << i))]++;
  }
}
void modify(int s, int p, int d) {
  upd(d);
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    modify(i, s, d ^ a[i]);
  }
}
long long ans;
void calc(int d) {
  for (int i = 0; i < 21; ++i) {
    int f = (bool)(d & (1 << i));
    ans += 1LL * dp[i][f ^ 1] * (1 << i);
  }
}
void Answer(int s, int p, int d) {
  calc(d);
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    Answer(i, s, d ^ a[i]);
  }
}
void decompose(int s, int p) {
  len = 0;
  dfs(s);
  int cen = Centroid(s, s);
  memset(dp, 0, sizeof dp);
  upd(a[cen]);
  for (int i : g[cen]) {
    if (vis[i]) continue;
    Answer(i, cen, a[i]);
    modify(i, cen, a[cen] ^ a[i]);
  }
  vis[cen] = 1;
  for (int i : g[cen]) {
    if (vis[i]) continue;
    decompose(i, cen);
  }
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    n = Int();
    for (int i = 1; i <= n; ++i) a[i] = Int(), ans += a[i];
    g.resize(n + 1);
    for (int i = 1; i < n; ++i) {
      int x = Int(), y = Int();
      g[x].push_back(y);
      g[y].push_back(x);
    }
    decompose(1, 1);
    printf("%lld\n", ans);
  }
  return 0;
}
