#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void stndrtn() {}
const int N = 1e5 + 10;
int sz[N];
vector<int> adj[N];
bool cntrd[N];
int a[N];
void calc(int x, int p = -1) {
  sz[x] = 1;
  for (int to : adj[x]) {
    if (to != p && !cntrd[to]) {
      calc(to, x);
      sz[x] += sz[to];
    }
  }
}
int szz = 0;
int fnd(int x, int p = -1) {
  for (int to : adj[x])
    if (to != p && !cntrd[to] && sz[to] > szz / 2) return fnd(to, x);
  return x;
}
ll ans[21];
int cnt[2][21];
void dfsplus(int x, int p, int xr) {
  xr ^= a[x];
  for (int i = 0; i < 20; ++i) cnt[bool(xr & (1 << i))][i]++;
  for (int to : adj[x])
    if (to != p && !cntrd[to]) dfsplus(to, x, xr);
}
void dfscalc(int x, int p, int xr = 0) {
  xr ^= a[x];
  for (int i = 0; i < 20; ++i) ans[i] += cnt[!bool(xr & (1 << i))][i];
  for (int to : adj[x])
    if (to != p && !cntrd[to]) dfscalc(to, x, xr);
}
void DnC(int x = 0) {
  calc(x);
  szz = sz[x];
  x = fnd(x);
  cntrd[x] = 1;
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < 20; ++i) cnt[bool(a[x] & (1 << i))][i]++;
  for (int to : adj[x]) {
    if (!cntrd[to]) {
      dfscalc(to, x);
      dfsplus(to, x, a[x]);
    }
  }
  for (int to : adj[x])
    if (!cntrd[to]) DnC(to);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr), stndrtn();
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DnC();
  for (int i = 0; i < 20; ++i) {
    sum += (1 << i) * ans[i];
  }
  cout << sum;
  return 0;
}
