#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > a;
long long zn[1000000];
long long kol[1000000];
long long ans = 0;
bool mrk[1000000];
long long kol1;
long long Kol(long long x, long long pr) {
  if (mrk[x]) return 0;
  kol[x] = 1;
  for (long long i = 0; i < a[x].size(); i++)
    if (a[x][i] != pr) kol[x] += Kol(a[x][i], x);
  return kol[x];
}
long long Centroid(long long x, long long pr) {
  for (long long i = 0; i < a[x].size(); i++)
    if (a[x][i] != pr && !mrk[a[x][i]] && kol[a[x][i]] * 2 > kol1)
      return Centroid(a[x][i], x);
  return x;
}
void Rec(long long x, long long pr, long long xor1, vector<long long> *x1) {
  if (mrk[x]) return;
  xor1 ^= zn[x];
  x1->push_back(xor1);
  for (long long i = 0; i < a[x].size(); i++)
    if (a[x][i] != pr) Rec(a[x][i], x, xor1, x1);
}
void CentrTree(long long x) {
  if (mrk[x]) return;
  kol1 = Kol(x, x);
  x = Centroid(x, x);
  long long koled[25], kolnull[25];
  for (long long i = 0; i < 25; i++) kolnull[i] = 0, koled[i] = 0;
  for (long long i = 0; i < a[x].size(); i++) {
    vector<long long> bits;
    Rec(a[x][i], x, 0, &bits);
    for (long long j = 0; j < bits.size(); j++) {
      for (long long c = 0; c < 25; c++)
        if ((bits[j] >> c) & 1)
          ans += (kolnull[c] * (1 << c));
        else
          ans += (koled[c] * (1 << c));
    }
    for (long long j = 0; j < bits.size(); j++) bits[j] ^= zn[x];
    for (long long j = 0; j < bits.size(); j++) ans += bits[j];
    for (long long j = 0; j < bits.size(); j++) {
      for (long long c = 0; c < 25; c++)
        if ((bits[j] >> c) & 1)
          koled[c]++;
        else
          kolnull[c]++;
    }
  }
  mrk[x] = 1;
  for (long long i = 0; i < a[x].size(); i++) CentrTree(a[x][i]);
}
int main() {
  long long n;
  cin >> n;
  a.resize(n);
  for (long long i = 0; i < n; i++) cin >> zn[i];
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    a[--x].push_back(--y);
    a[y].push_back(x);
  }
  CentrTree(0);
  for (long long i = 0; i < n; i++) ans += zn[i];
  cout << ans;
}
