#include <bits/stdc++.h>
using namespace std;
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int n;
long long ara[100010];
vector<int> adjl[100010], lev[100010];
int par[100010];
int mxlev = 0;
void func(int u, int lv) {
  mxlev = max(mxlev, lv);
  lev[lv].push_back(u);
  for (int i = 0; i <= (int)adjl[u].size() - 1; i++) {
    int v = adjl[u][i];
    if (v == par[u]) {
      continue;
    }
    par[v] = u;
    func(v, lv + 1);
  }
}
pair<long long, long long> ans[100010];
pair<long long, long long> mot;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adjl[u].push_back(v);
    adjl[v].push_back(u);
  }
  func(1, 0);
  long long foo = 0;
  long long gun = 1;
  for (int bit = 0; bit <= 20; bit++) {
    memset(ans, 0, sizeof(ans));
    mot = {0, 0};
    for (int lv = mxlev; lv >= 0; lv--) {
      for (int i = 0; i <= (int)lev[lv].size() - 1; i++) {
        int u = lev[lv][i];
        pair<long long, long long> csum = {0, 0};
        for (int j = 0; j <= (int)adjl[u].size() - 1; j++) {
          int v = adjl[u][j];
          if (v == par[u]) {
            continue;
          }
          ans[u].first += ans[v].first;
          ans[u].second += ans[v].second;
          if (ara[u] & (1 << bit)) {
            mot.second += (csum.second * ans[v].second);
            mot.second += (csum.first * ans[v].first);
          } else {
            mot.second += (csum.first * ans[v].second);
            mot.second += (csum.second * ans[v].first);
          }
          csum.first += ans[v].first;
          csum.second += ans[v].second;
        }
        if (ara[u] & (1 << bit)) {
          swap(ans[u].first, ans[u].second);
          ans[u].second++;
        } else {
          ans[u].first++;
        }
        mot.second += ans[u].second;
      }
    }
    foo += (mot.second * gun);
    gun *= 2LL;
  }
  cout << foo;
  return 0;
}
