#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5, logn = 25;
vector<long long> g[maxn];
long long a[maxn], x[maxn], y[maxn];
long long ans = 0;
void zhfs(long long v, long long p, long long l) {
  x[v] = y[v] = 0;
  for (long long u : g[v]) {
    if (u == p) continue;
    zhfs(u, v, l);
    if (a[v] & (1ll << l))
      ans += (1ll << l) * (x[v] * x[u] + y[v] * y[u]);
    else
      ans += (1 << l) * (x[v] * y[u] + y[v] * x[u]);
    x[v] += x[u], y[v] += y[u];
  }
  if (a[v] & (1 << l)) {
    ans += (1ll << l) * (1 + y[v]);
    swap(x[v], y[v]);
    x[v]++;
  } else {
    ans += (1ll << l) * x[v];
    y[v]++;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (long long l = 0; l < logn; l++) zhfs(0, -1, l);
  cout << ans;
  return 0;
}
