#include <bits/stdc++.h>
using namespace std;
const int MXN = 100005;
const int second = 20;
struct HHSet {
  int cnt[second][2];
  void add(int x) {
    for (int i = 0; i < (second); i++) cnt[i][(x >> i) & 1]++;
  }
} s[MXN];
int N, ip[MXN], val[MXN], sid[MXN];
long long ans;
vector<int> E[MXN];
int merge(int a, int b, int lca) {
  for (int i = 0; i < (second); i++) {
    long long one, zero;
    one = zero = 0;
    zero += 1LL * s[a].cnt[i][0] * s[b].cnt[i][0];
    zero += 1LL * s[a].cnt[i][1] * s[b].cnt[i][1];
    one += 1LL * s[a].cnt[i][0] * s[b].cnt[i][1];
    one += 1LL * s[a].cnt[i][1] * s[b].cnt[i][0];
    if ((ip[lca] >> i) & 1) swap(one, zero);
    ans += one << i;
    s[a].cnt[i][0] += s[b].cnt[i][0];
    s[a].cnt[i][1] += s[b].cnt[i][1];
  }
  return a;
}
void DFS(int u, int f) {
  val[u] = val[f] ^ ip[u];
  sid[u] = u;
  s[u].add(val[u]);
  for (auto v : E[u]) {
    if (v == f) continue;
    DFS(v, u);
    sid[u] = merge(sid[u], sid[v], u);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> N;
  for (int i = (1); i <= (N); i++) cin >> ip[i];
  for (int _ = 0; _ < (N - 1); _++) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  ans = 0;
  DFS(1, 1);
  for (int i = (1); i <= (N); i++) ans += ip[i];
  cout << ans << endl;
  return 0;
}
