#include <bits/stdc++.h>
using namespace std;
int a[100005];
int head[100005];
struct node {
  int u, v, nex;
} edge[200005];
int cnt;
long long ans;
void add(int u, int v) {
  edge[cnt].u = u;
  edge[cnt].v = v;
  edge[cnt].nex = head[u];
  head[u] = cnt++;
}
long long num[100005][2];
void dfs(int u, int fa, int bit) {
  int t = (a[u] >> bit) & (1);
  num[u][t] = 1;
  num[u][t ^ 1] = 0;
  long long sum = 0;
  for (int i = head[u]; i != -1; i = edge[i].nex) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs(v, u, bit);
    sum += (num[u][0] * num[v][1] + num[u][1] * num[v][0]);
    num[u][0 ^ t] += num[v][0];
    num[u][1 ^ t] += num[v][1];
  }
  ans += (long long)sum * (1 << bit);
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    cnt = 0;
    ans = 0;
    for (int i = 1; i <= n; i++) {
      head[i] = -1;
      scanf("%d", &a[i]);
      ans += a[i];
    }
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
      add(v, u);
    }
    for (int i = 0; i < 30; i++) {
      dfs(1, -1, i);
    }
    printf("%lld\n", ans);
  }
}
