#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
long long c[32];
vector<int> ad[100005];
int a[100005];
int d[100005][2];
pair<int, int> dfs(int no, int p, int v) {
  long long s1 = 0, s0 = 0, an = 0;
  pair<int, int> te;
  for (long long i = 0; i < ad[no].size(); i++) {
    if (ad[no][i] != p) {
      te = dfs(ad[no][i], no, v);
      if (a[no] & (1 << v)) {
        s1 += te.first;
        s0 += te.second;
      } else {
        s0 += te.first;
        s1 += te.second;
      }
    }
  }
  for (long long i = 0; i < ad[no].size(); i++) {
    if (ad[no][i] != p) {
      if (a[no] & (1 << v)) {
        an += (s1 - d[ad[no][i]][0]) * (d[ad[no][i]][0]);
        an += (s0 - d[ad[no][i]][1]) * (d[ad[no][i]][1]);
      } else {
        an += (s1 - d[ad[no][i]][1]) * (d[ad[no][i]][0]);
        an += (s0 - d[ad[no][i]][0]) * (d[ad[no][i]][1]);
      }
    }
  }
  if (a[no] & (1 << v))
    s1++;
  else
    s0++;
  d[no][0] = s0;
  d[no][1] = s1;
  c[v] += an / 2;
  c[v] += s1;
  return {s0, s1};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(c, 0, sizeof(c));
  int n, t1, t2;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  for (long long i = 0; i < n - 1; i++) {
    cin >> t1 >> t2;
    ad[t1].push_back(t2);
    ad[t2].push_back(t1);
  }
  for (long long i = 0; i < 32; i++) dfs(1, -1, i);
  long long an = 0;
  for (long long i = 0; i < 32; i++) an += c[i] * (1 << i);
  cout << an << "\n";
  return 0;
}
