#include <bits/stdc++.h>
using namespace std;
int a[100005];
vector<int> AdjList[100005];
vector<int> AdjList2[100005];
int b[100005];
int cnt[100005][2];
int p[100005];
void findParent(int u, int p2) {
  p[u] = p2;
  for (int v : AdjList[u]) {
    if (v != p2) {
      findParent(v, u);
    }
  }
}
void dfs(int u) {
  cnt[u][0] = 0;
  cnt[u][1] = 0;
  cnt[u][b[u]]++;
  for (int v : AdjList2[u]) {
    dfs(v);
    for (int i = 0; i < 2; i++) {
      cnt[u][i ^ b[u]] += cnt[v][i];
    }
  }
}
long long total = 0;
void reroot(int u) {
  int cntU[2];
  int cntV[2];
  total += cnt[u][1];
  for (int v : AdjList2[u]) {
    for (int i = 0; i < 2; i++) {
      cntU[i] = cnt[u][i];
      cntV[i] = cnt[v][i];
    }
    for (int i = 0; i < 2; i++) {
      cnt[u][i] -= cntV[i ^ b[u]];
      cnt[v][i ^ b[v]] += cnt[u][i];
    }
    reroot(v);
    for (int i = 0; i < 2; i++) {
      cnt[u][i] = cntU[i];
      cnt[v][i] = cntV[i];
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    AdjList[u].push_back(v);
    AdjList[v].push_back(u);
  }
  findParent(1, -1);
  for (int i = 2; i <= n; i++) {
    AdjList2[p[i]].push_back(i);
  }
  long long ans = 0;
  for (int k = 0; k < 20; k++) {
    for (int i = 1; i <= n; i++) {
      b[i] = (a[i] & (1 << k)) != 0;
    }
    dfs(1);
    total = 0;
    reroot(1);
    ans += (total << k);
  }
  for (int i = 1; i <= n; i++) {
    ans += a[i];
  }
  ans >>= 1;
  printf("%lld\n", ans);
  return 0;
}
