#include <bits/stdc++.h>
using namespace std;
inline void pin(int n) { printf("%d\n", n); }
double PI = acos(-1);
const int inf = 0x3f3f3f3f;
long long int StoI(string &s) {
  long long int sum = 0;
  for (long long int i = 0; i < s.size(); i++) {
    s[i] -= '0';
    sum = sum * 10 + s[i];
  }
  return sum;
}
long long int power(long long int a, long long int n) {
  long long int p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long int power(long long int a, long long int n, long long int mod) {
  long long int p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
int n;
vector<int> g[100005];
vector<int> val(100005);
long long int res;
long long int dp[100005][25][2];
void dfs(int q, int p) {
  long long int cans[25][2];
  memset(cans, 0, sizeof cans);
  for (auto x : g[q]) {
    if (x == p) continue;
    dfs(x, q);
  }
  for (auto x : g[q]) {
    if (x == p) continue;
    for (int i = 0; i < 25; i++) {
      long long int xxs, yyo;
      if ((val[q] >> i) & 1) {
        xxs = dp[x][i][0];
        yyo = dp[x][i][1];
      } else {
        xxs = dp[x][i][1];
        yyo = dp[x][i][0];
      }
      res += (xxs << i);
      dp[q][i][1] += xxs;
      dp[q][i][0] += yyo;
    }
  }
  for (auto x : g[q]) {
    if (x == p) continue;
    long long int xxs, yyo;
    for (int i = 0; i < 25; i++) {
      if ((val[q] >> i) & 1) {
        xxs = cans[i][1] * dp[x][i][1] + cans[i][0] * dp[x][i][0];
        yyo = cans[i][1] * dp[x][i][0] + cans[i][0] * dp[x][i][1];
      } else {
        yyo = cans[i][1] * dp[x][i][1] + cans[i][0] * dp[x][i][0];
        xxs = cans[i][1] * dp[x][i][0] + cans[i][0] * dp[x][i][1];
      }
      cans[i][1] += dp[x][i][1];
      cans[i][0] += dp[x][i][0];
      res += (xxs << i);
    }
  }
  for (int i = 0; i < 25; i++) {
    dp[q][i][(val[q] >> i) & 1]++;
    res += ((val[q] >> i) & 1) << i;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> val[i];
  res = 0;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1);
  cout << res;
  return 0;
}
