#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 100000 + 5;
const double eps = 1e-6;
const double PI = acos(-1.0);
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void fre() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
inline long long int gcd(long long int a, long long int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
int a[N], b[N], cnt[N][2];
vector<int> E[N];
long long int sum;
void dfs(int u, int fa) {
  cnt[u][0] = cnt[u][1] = 0;
  cnt[u][b[u]]++;
  sum += b[u];
  int v;
  for (int i = 0; i < E[u].size(); i++) {
    v = E[u][i];
    if (v == fa) continue;
    dfs(v, u);
    sum += cnt[u][0] * cnt[v][1] + cnt[u][1] * cnt[v][0];
    cnt[u][b[u]] += cnt[v][0];
    cnt[u][b[u] ^ 1] += cnt[v][1];
  }
}
int main() {
  int n, u, v;
  n = read();
  for (int i = (1); i <= (n); i++) a[i] = read(), E[i].clear();
  for (int i = (2); i <= (n); i++) {
    u = read(), v = read();
    E[u].push_back(v);
    E[v].push_back(u);
  }
  long long int ans = 0ll;
  for (int i = (0); i <= (20); i++) {
    for (int j = (1); j <= (n); j++) {
      if (a[j] & (1 << i))
        b[j] = 1;
      else
        b[j] = 0;
    }
    sum = 0ll;
    dfs(1, -1);
    ans += sum * (1 << i);
  }
  printf("%I64d\n", ans);
  return 0;
}
