#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 7;
long long n, a[NMAX], sz[NMAX], mark[NMAX], sol;
long long all_bit, all_bit1, cnt_bit[22], cnt_bit1[22];
vector<int> g[NMAX];
void dfs(int u, int pre) {
  sz[u] = 1;
  for (auto v : g[u]) {
    if (v != pre && !mark[v]) {
      dfs(v, u);
      sz[u] += sz[v];
    }
  }
}
void _do(int cur, int prev, long long d, int src) {
  long long now = d ^ a[src];
  sol += now;
  for (int i = 0; i < 22; i++) {
    if (now & (1 << i))
      sol += (1ll << i) * (all_bit - cnt_bit[i]);
    else
      sol += (1 << i) * cnt_bit[i];
  }
  for (int i = 0; i < 22; i++) {
    if (d & (1ll << i)) cnt_bit1[i]++;
  }
  all_bit1++;
  for (auto it : g[cur]) {
    if (it != prev && !mark[it]) _do(it, cur, d ^ a[it], src);
  }
}
void centroid(int u) {
  dfs(u, 0);
  int st = u;
  int par = -1;
  while (1) {
    int _found = true;
    for (auto it : g[st]) {
      if (it != par && !mark[it] && sz[it] > sz[u] / 2) {
        par = st;
        st = it;
        _found = false;
        break;
      }
    }
    if (_found) break;
  }
  sol += a[st];
  memset(cnt_bit, 0, sizeof(cnt_bit));
  all_bit = 0;
  for (auto it : g[st]) {
    if (!mark[it]) {
      memset(cnt_bit1, 0, sizeof(cnt_bit1));
      all_bit1 = 0;
      _do(it, st, a[it], st);
      for (int i = 0; i < 22; i++) cnt_bit[i] += cnt_bit1[i];
      all_bit += all_bit1;
    }
  }
  mark[st] = 1;
  for (auto it : g[st])
    if (!mark[it]) centroid(it);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  centroid(1);
  printf("%I64d\n", sol);
  return 0;
}
