#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000000 + 7;
const long long INF = 1000000LL * 1000000LL * 1000000LL;
int n, a, b;
long long res;
int Val[100000 + 7];
int Act[100000 + 7];
int Deg[100000 + 7];
long long DP[100000 + 7][2];
bool Vis[100000 + 7];
vector<int> V;
vector<int> Graph[100000 + 7];
queue<int> Q;
void Modify(int);
long long Solve();
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &Val[i]);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }
  for (int i = 0; i <= 20; i++) {
    Modify(1 << i);
    res += Solve() * (1 << i);
  }
  printf("%lld\n", res);
}
void Modify(int x) {
  for (int i = 1; i <= n; i++) {
    Act[i] = ((Val[i] & x) != 0);
  }
}
long long Solve() {
  long long ile = 0;
  for (int i = 1; i <= n; i++) {
    Vis[i] = false;
    DP[i][0] = DP[i][1] = 0;
    Deg[i] = (int)(Graph[i]).size();
    if ((int)(Graph[i]).size() <= 1) {
      Q.push(i);
      Vis[i] = true;
    }
  }
  while (!Q.empty()) {
    int v = Q.front();
    long long zero = 0;
    long long one = 0;
    Q.pop();
    for (int i = 0; i < (int)(Graph[v]).size(); i++) {
      int u = Graph[v][i];
      Deg[u]--;
      if (Vis[u]) {
        V.push_back(u);
        zero += DP[u][0];
        one += DP[u][1];
      } else if (Deg[u] == 1 && !Vis[u]) {
        Vis[u] = true;
        Q.push(u);
      }
    }
    long long sum = 0;
    for (int i = 0; i < (int)(V).size(); i++) {
      int x = V[i];
      zero -= DP[x][0];
      one -= DP[x][1];
      if (Act[v] == 0) {
        sum += DP[x][0] * one;
        sum += DP[x][1] * zero;
      } else {
        sum += DP[x][1] * one;
        sum += DP[x][0] * zero;
      }
      zero += DP[x][0];
      one += DP[x][1];
    }
    ile += sum / 2;
    DP[v][0] += zero;
    DP[v][1] += one;
    if (Act[v] == 1) swap(DP[v][0], DP[v][1]);
    DP[v][Act[v]]++;
    ile += DP[v][1];
    V.clear();
  }
  return ile;
}
