#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
int n, a[MAXN], cnt1[MAXN][21], cnt2[MAXN][21], pw[21];
long long ans;
vector<int> g[MAXN];
bool visited[MAXN], c[MAXN][21];
void dfs(int v, int p) {
  visited[v] = true;
  for (int i = 0; i <= 20; i++) {
    c[v][i] = (((p >> i) & 1) ^ ((a[v] >> i) & 1));
  }
  for (auto u : g[v]) {
    if (!visited[u]) {
      dfs(u, p ^ a[v]);
      for (int i = 0; i <= 20; i++) {
        if (((a[v] >> i) & 1) && c[v][i]) {
          ans += 1LL * cnt1[u][i] * pw[i];
          ans += 1LL * cnt1[u][i] * cnt1[v][i] * pw[i];
          ans += 1LL * cnt2[u][i] * cnt2[v][i] * pw[i];
        } else if ((a[v] >> i) & 1) {
          ans += 1LL * cnt2[u][i] * pw[i];
          ans += 1LL * cnt1[u][i] * cnt1[v][i] * pw[i];
          ans += 1LL * cnt2[u][i] * cnt2[v][i] * pw[i];
        } else if (c[v][i]) {
          ans += 1LL * cnt2[u][i] * pw[i];
          ans += 1LL * cnt1[u][i] * cnt2[v][i] * pw[i];
          ans += 1LL * cnt2[u][i] * cnt1[v][i] * pw[i];
        } else {
          ans += 1LL * cnt1[u][i] * pw[i];
          ans += 1LL * cnt1[u][i] * cnt2[v][i] * pw[i];
          ans += 1LL * cnt2[u][i] * cnt1[v][i] * pw[i];
        }
      }
      for (int i = 0; i <= 20; i++) {
        cnt1[v][i] += cnt1[u][i];
        cnt2[v][i] += cnt2[u][i];
      }
    }
  }
  for (int i = 0; i <= 20; i++) {
    if (c[v][i]) {
      cnt1[v][i]++;
    } else {
      cnt2[v][i]++;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  pw[0] = 1;
  for (int i = 1; i <= 20; i++) {
    pw[i] = pw[i - 1] << 1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans;
  return 0;
}
