#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int cnt[MAXN][21][2];
int w[MAXN];
long long ans = 0;
vector<int> g[MAXN];
void query(int u, int p) {
  for (int i = 0; i <= 20; ++i) {
    for (int j = 0; j <= 1; ++j) {
      int me = cnt[u][i][j];
      int he = cnt[p][i][1 - j];
      long long mul = (long long)me * he;
      ans += (1 << i) * mul;
    }
  }
}
void update(int u, int p) {
  for (int i = 0; i <= 20; ++i) {
    int c = (w[p] & (1 << i)) ? 1 : 0;
    for (int j = 0; j <= 1; ++j) {
      cnt[p][i][j ^ c] += cnt[u][i][j];
    }
  }
}
void dfs(int u, int p = 0) {
  for (int i = 0; i <= 20; ++i) {
    int c = (w[u] & (1 << i)) ? 1 : 0;
    ++cnt[u][i][c];
  }
  ans += w[u];
  for (auto v : g[u]) {
    if (v != p) {
      dfs(v, u);
      query(v, u);
      update(v, u);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &w[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);
  }
  dfs(1);
  printf("%lld\n", ans);
}
