#include <bits/stdc++.h>
using namespace std;
int n;
int A[100010];
vector<vector<int> > tree;
bool visited[100010];
int size[100010];
int pre[20][2];
long long ans;
int calcSize(int u) {
  visited[u] = true;
  int sz = 1;
  int v;
  for (int i = 0; i < tree[u].size(); ++i) {
    v = tree[u][i];
    if (!visited[v]) sz += calcSize(v);
  }
  return size[u] = sz;
}
int getCentroid(int u) {
  int v;
  int root = u;
  for (int i = 0; i < (int)tree[u].size(); ++i) {
    v = tree[u][i];
    if (visited[v]) continue;
    if (size[v] > size[u] / 2) {
      root = v;
      break;
    }
  }
  if (root != u) {
    size[u] -= size[v];
    size[v] += size[u];
    return getCentroid(v);
  }
  return u;
}
void dfs(int u, int fa, int now) {
  for (int i = 0; i < 20; ++i)
    if (now & (1 << i))
      ans += (1LL << i) * (long long)pre[i][0];
    else
      ans += (1LL << i) * (long long)pre[i][1];
  int v;
  for (int i = 0; i < tree[u].size(); ++i) {
    v = tree[u][i];
    if (v == fa || visited[v]) continue;
    dfs(v, u, now ^ A[v]);
  }
}
void Dfs(int u, int fa, int now) {
  for (int i = 0; i < 20; ++i)
    if (now & (1 << i))
      pre[i][1]++;
    else
      pre[i][0]++;
  int v;
  for (int i = 0; i < tree[u].size(); ++i) {
    v = tree[u][i];
    if (v == fa || visited[v]) continue;
    Dfs(v, u, now ^ A[v]);
  }
}
void solve(int u) {
  int root = getCentroid(u);
  visited[root] = true;
  memset(pre, 0, sizeof pre);
  for (int i = 0; i < 20; ++i)
    if (A[root] & (1 << i))
      pre[i][1] = 1;
    else
      pre[i][0] = 1;
  int v;
  for (int i = 0; i < (int)tree[root].size(); ++i) {
    v = tree[root][i];
    if (visited[v]) continue;
    dfs(v, root, A[v]);
    Dfs(v, root, A[v] ^ A[root]);
  }
  for (int i = 0; i < (int)tree[root].size(); ++i) {
    v = tree[root][i];
    if (!visited[v]) solve(v);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  tree.assign(n, vector<int>());
  ans = 0;
  for (int i = 0; i < n; ++i) cin >> A[i], ans += A[i];
  int u, v;
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    u--;
    v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  memset(size, 0, sizeof size);
  memset(visited, 0, sizeof visited);
  calcSize(0);
  memset(visited, 0, sizeof visited);
  memset(pre, 0, sizeof pre);
  solve(0);
  cout << ans << "\n";
  return 0;
}
