#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 41;
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 2e9;
vector<int> g[N];
long long res;
int cnt[2];
int a[N];
int sz[N];
bool used[N];
int cur_sz;
long long cur;
void pre(int v = 1, int p = -1) {
  sz[v] = 1;
  for (int to : g[v])
    if (to != p && !used[to]) {
      pre(to, v);
      sz[v] += sz[to];
    }
}
int f(int v, int p = -1) {
  for (int to : g[v])
    if (!used[to] && to != p && sz[to] * 2 > cur_sz) {
      return f(to, v);
    }
  return v;
}
bool kth(int val, int bit) {
  if (val & (1 << bit))
    return true;
  else
    return false;
}
void addcur(int v, int p, int bit, bool pref = 0) {
  pref ^= kth(a[v], bit);
  cur += cnt[pref ^ 1];
  for (int to : g[v])
    if (!used[to] && to != p) {
      addcur(to, v, bit, pref);
    }
}
void addcnt(int v, int p, int bit, bool pref = 0) {
  pref ^= kth(a[v], bit);
  cnt[pref]++;
  for (int to : g[v])
    if (!used[to] && to != p) {
      addcnt(to, v, bit, pref);
    }
}
void dfs(int v = 1) {
  pre(v);
  cur_sz = sz[v];
  v = f(v);
  for (int bit = 0; bit < 20; ++bit) {
    cur = 0;
    cnt[1] = 0, cnt[0] = 1;
    for (int to : g[v])
      if (!used[to]) {
        bool st = kth(a[v], bit);
        addcur(to, v, bit, st);
        addcnt(to, v, bit);
      }
    res += (1ll << bit) * 1ll * cur;
  }
  used[v] = 1;
  for (int to : g[v])
    if (!used[to]) {
      dfs(to);
    }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    res += a[i];
  }
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs();
  cout << res;
}
