#include <bits/stdc++.h>
using namespace std;
const int max_n = 100011, log_n = 32, max_m = 111, mod = 1000000007,
          inf = 1011111111, p = 997;
long long n, pp[22], dp[max_n][22][2];
bool a[max_n][22];
long long ans;
vector<int> v[max_n];
void dfs(int x, int p) {
  for (int i = 0; i < v[x].size(); ++i) {
    if (v[x][i] == p) continue;
    dfs(v[x][i], x);
    for (int q = 0; q < 22; ++q) {
      dp[x][q][a[x][q]] += dp[v[x][i]][q][0];
      dp[x][q][1 - a[x][q]] += dp[v[x][i]][q][1];
    }
  }
  long long ans1 = 0;
  for (int i = 0; i < v[x].size(); ++i) {
    if (v[x][i] == p) continue;
    for (int q = 0; q < 22; ++q) {
      dp[x][q][a[x][q]] -= dp[v[x][i]][q][0];
      dp[x][q][1 - a[x][q]] -= dp[v[x][i]][q][1];
      ans1 += pp[q] * dp[v[x][i]][q][0] * dp[x][q][1];
      ans1 += pp[q] * dp[v[x][i]][q][1] * dp[x][q][0];
      dp[x][q][a[x][q]] += dp[v[x][i]][q][0];
      dp[x][q][1 - a[x][q]] += dp[v[x][i]][q][1];
    }
  }
  ans1 /= 2;
  ans += ans1;
  for (int i = 0; i < 22; ++i) {
    dp[x][i][a[x][i]]++;
    ans += pp[i] * dp[x][i][1];
  }
}
int main() {
  pp[0] = 1;
  for (int i = 1; i < 22; ++i) {
    pp[i] = pp[i - 1] * 2;
  }
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int g;
    cin >> g;
    for (int q = 0; g; g /= 2, ++q) {
      a[i][q] = g % 2;
    }
  }
  for (int i = 1; i < n; ++i) {
    int g, h;
    cin >> g >> h;
    g--;
    h--;
    v[g].push_back(h);
    v[h].push_back(g);
  }
  dfs(0, -1);
  cout << ans << endl;
  return 0;
}
