#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, mod = 1e9 + 9, inf = 1e9 + 7;
const long long linf = (long long)1e18 + 7;
const long double eps = 1e-15, pi = 3.141592;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1},
          dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
inline int get_int() {
  char x = getchar();
  while (!('0' <= x && x <= '9')) x = getchar();
  int res = 0;
  while ('0' <= x && x <= '9') res = res * 10 + x - '0', x = getchar();
  return res;
}
int n;
int a[N], sz[N], path[N], deep[N], cnt[21][2];
long long ans[N];
vector<int> g[N];
inline void precalc(int v = 1, int p = 1) {
  deep[v] = deep[p] + 1, path[v] = path[p] ^ a[v];
  for (auto i : g[v])
    if (i != p) precalc(i, v), sz[v] += sz[i];
  if (v > 1) g[v].erase(find(g[v].begin(), g[v].end(), p));
}
inline void upd(int v, int x) {
  for (int i = 0; i <= 20; ++i) {
    if (path[v] & (1 << i))
      cnt[i][1] += x;
    else
      cnt[i][0] += x;
  }
  for (auto i : g[v]) upd(i, x);
}
inline void calc(int v, int add) {
  for (int i = 0; i <= 20; ++i) {
    if (path[v] & (1 << i)) {
      if (a[add] & (1 << i))
        ans[add] += (1LL << i) * cnt[i][1];
      else
        ans[add] += (1LL << i) * cnt[i][0];
    } else {
      if (a[add] & (1 << i))
        ans[add] += (1LL << i) * cnt[i][0];
      else
        ans[add] += (1LL << i) * cnt[i][1];
    }
  }
  for (auto i : g[v]) calc(i, add);
}
inline void dfs(int v = 1, int p = 1, bool keep = 0) {
  int mx = -1, id = -1;
  for (auto i : g[v])
    if (i != p && sz[i] > mx) mx = sz[i], id = i;
  for (auto i : g[v])
    if (i != p && i != id) dfs(i, v, 0), ans[v] += ans[i];
  if (id != -1) dfs(id, v, 1), ans[v] += ans[id];
  for (auto i : g[v])
    if (i != p && i != id) calc(i, v), upd(i, 1);
  for (int i = 0; i <= 20; ++i) {
    if (path[v] & (1 << i)) {
      cnt[i][1]++;
      if (a[v] & (1 << i))
        ans[v] += (1LL << i) * cnt[i][1];
      else
        ans[v] += (1LL << i) * cnt[i][0];
    } else {
      cnt[i][0]++;
      if (a[v] & (1 << i))
        ans[v] += (1LL << i) * cnt[i][0];
      else
        ans[v] += (1LL << i) * cnt[i][1];
    }
  }
  if (!keep && v != 1) upd(v, -1);
}
int main() {
  n = get_int();
  for (int i = 1; i <= n; ++i) a[i] = get_int();
  for (int i = 2; i <= n; ++i) {
    int v, u;
    v = get_int();
    u = get_int();
    g[v].push_back(u);
    g[u].push_back(v);
  }
  precalc(), dfs();
  cout << ans[1];
  exit(0);
}
