#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> cur(20, vector<long long int>(2));
vector<long long int> adj[(long long int)(2e5 + 5)],
    s((long long int)(2e5 + 5)), a((long long int)(2e5 + 5));
vector<bool> mrk((long long int)(2e5 + 5));
long long int dfs(long long int c, long long int pre = 0) {
  s[c] = 1;
  for (auto x : adj[c]) {
    if (x == pre || mrk[x]) continue;
    s[c] += dfs(x, c);
  }
  return s[c];
}
long long int get(long long int c, long long int pre, long long int ts) {
  for (auto x : adj[c]) {
    if (mrk[x] || x == pre) continue;
    if (2 * s[x] > ts) return get(x, c, ts);
  }
  return c;
}
void sumdfs(long long int c, long long int pre, long long int xcur = 0) {
  xcur ^= a[c];
  for (long long int i = 0; i < 20; i++) cur[i][(xcur >> i) & 1]++;
  for (auto x : adj[c]) {
    if (x == pre || mrk[x]) continue;
    sumdfs(x, c, xcur);
  }
}
long long int centroid(long long int c) {
  c = get(c, 0, dfs(c));
  mrk[c] = 1;
  long long int res = a[c];
  vector<vector<long long int>> tot(20, vector<long long int>(2));
  for (long long int i = 0; i < 20; i++) tot[i][(a[c] >> i) & 1]++;
  for (auto x : adj[c])
    if (!mrk[x]) {
      for (long long int i = 0; i < 20; i++) cur[i][1] = cur[i][0] = 0;
      sumdfs(x, c);
      for (long long int i = 0; i < 20; i++) {
        res += (1 << i) * (tot[i][0] * cur[i][1] + tot[i][1] * cur[i][0]);
        bool w = (a[c] >> i) & 1;
        tot[i][0] += cur[i][w];
        tot[i][1] += cur[i][w ^ 1];
      }
    }
  for (auto x : adj[c])
    if (!mrk[x]) res += centroid(x);
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i < n; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cout << centroid(1);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
