#include <bits/stdc++.h>
using namespace std;
long long exp(long long b, long long e) {
  if (b == 1 || e == 0) return 1;
  if (e == 1) return b % 1000000007;
  if (e == 2) return (b * b) % 1000000007;
  return ((e % 2 == 0)
              ? exp(exp(b, e / 2), 2) % 1000000007
              : (b * (exp(exp(b, e / 2), 2) % 1000000007)) % 1000000007);
}
long long gcd(long long a, long long b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
int a[100005], n;
vector<int> adj[100005];
long long ans = 0;
pair<long long, long long> dfs(int v, int p, int bit) {
  vector<pair<long long, long long> > r;
  long long sum[2] = {0, 0};
  for (vector<int>::iterator it = adj[v].begin(), ite = adj[v].end(); it != ite;
       ++it) {
    if (*it == p) continue;
    pair<long long, long long> t;
    r.push_back(t = dfs(*it, v, bit));
    sum[1] += t.first;
    sum[0] += t.second;
  }
  long long ret = 0;
  int t = ((a[v] & (1 << bit)) > 0);
  for (int i = 0; i < adj[v].size(); ++i) {
    if (v != 1 && i == adj[v].size() - 1) continue;
    if (t == 0) {
      ret += (r[i].first * (sum[0] - r[i].second));
      ret += (r[i].second * (sum[1] - r[i].first));
    } else {
      ret += (r[i].second * (sum[0] - r[i].second));
      ret += (r[i].first * (sum[1] - r[i].first));
    }
  }
  ans += (((ret >> 1) + sum[(t + 1) & 1] + (t & 1)) * (1 << bit));
  if (bit <= 3) {
  }
  r.clear();
  if (t == 0)
    return make_pair(sum[1], sum[0] + 1);
  else
    return make_pair(sum[0] + 1, sum[1]);
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  ans = 0;
  for (int i = 20; i >= 0; --i) {
    dfs(1, 0, i);
  }
  printf("%lld\n", ans);
  return 0;
}
