#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > ad(100005);
long long int dp[100005][20];
int ar[100005][20], vis[100005];
long long int po[20], cnt[100005];
long long int ans;
void dfs(int s) {
  int i, j, a, x = ad[s].size();
  vis[s] = 1;
  long long int node = 0, nod2 = 0;
  vector<long long int> tot(20, 0), tot2(20, 0), tono(20, 0);
  for (i = 0; i < x; i++) {
    a = ad[s][i];
    if (vis[a] == 0) {
      dfs(a);
      node += cnt[a];
      nod2 += (cnt[a] * cnt[a]);
      for (j = 0; j < 20; j++) {
        tot[j] += dp[a][j];
        tot2[j] += (dp[a][j] * dp[a][j]);
        tono[j] += (dp[a][j] * cnt[a]);
      }
    }
  }
  cnt[s] = 1 + node;
  for (j = 0; j < 20; j++) {
    if (ar[s][j] == 0) {
      dp[s][j] = tot[j];
      ans += po[j] *
             (dp[s][j] + node * tot[j] - tono[j] + tot2[j] - tot[j] * tot[j]);
    } else {
      dp[s][j] = cnt[s] - tot[j];
      ans += po[j] * (dp[s][j] - node * tot[j] + tono[j] - tot2[j] +
                      tot[j] * tot[j] + (node * node - nod2) / 2);
    }
  }
  return;
}
int main() {
  int n, i, j, x, a, b;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    for (j = 0; j < 20; j++) ar[i][j] = (x & 1), x /= 2;
  }
  po[0] = 1;
  for (i = 1; i < 20; i++) po[i] = 2 * po[i - 1];
  for (i = 1; i < n; i++) {
    scanf("%d", &a), scanf("%d", &b);
    a--, b--;
    ad[a].push_back(b);
    ad[b].push_back(a);
  }
  dfs(0);
  cout << ans << endl;
}
