#include <bits/stdc++.h>
using namespace std;
void In() { freopen("in.in", "r", stdin); }
void Out() { freopen("out.out", "w", stdout); }
const int N = 1e5 + 10;
const int M = 3e5 + 10;
const int Mbit = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-8;
int n;
vector<int> G[N];
int a[N], b[N], cnt[N][2];
long long sum;
void dfs(int u, int fa) {
  cnt[u][0] = cnt[u][1] = 0;
  cnt[u][b[u]]++;
  sum += b[u];
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[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() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  long long ans = 0;
  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 = 0;
    dfs(1, -1);
    ans += (sum << i);
  }
  printf("%lld\n", ans);
  return 0;
}
