#include <bits/stdc++.h>
using namespace std;
int a[200005], h[200005], tot, n, d[200005], c[200005][20], sz[200005];
long long ans;
struct edge {
  int to, nxt;
} e[200005 << 1];
void add(int x, int y) {
  e[++tot].nxt = h[x];
  h[x] = tot;
  e[tot].to = y;
}
void dfs(int x, int fa) {
  d[x] = d[fa] ^ a[x];
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].to != fa) {
      dfs(e[i].to, x);
      for (int j = 0; j <= 19; j++) {
        if (1 & (a[x] >> j))
          ans += 1LL * (1 << j) *
                 (1LL * c[x][j] * c[e[i].to][j] +
                  1LL * (sz[x] - c[x][j]) * (sz[e[i].to] - c[e[i].to][j]));
        else
          ans += 1LL * (1 << j) *
                 (1LL * c[x][j] * (sz[e[i].to] - c[e[i].to][j]) +
                  1LL * c[e[i].to][j] * (sz[x] - c[x][j]));
      }
      sz[x] += sz[e[i].to];
      for (int j = 0; j <= 19; j++) c[x][j] += c[e[i].to][j];
    }
  for (int j = 0; j <= 19; j++)
    if (1 & ((a[x] ^ d[x]) >> j))
      ans += 1LL * (1 << j) * (sz[x] - c[x][j]);
    else
      ans += 1LL * (1 << j) * c[x][j];
  ans += a[x];
  sz[x]++;
  for (int j = 0; j <= 19; j++)
    if (1 & (d[x] >> j)) c[x][j]++;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  printf("%lld\n", ans);
  return 0;
}
