#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int a[200005];
int del[200005], par[200005];
int now, tot;
int subtree[200005];
int bit[35];
void dfs(int node, int p) {
  subtree[node] = 1;
  tot++;
  int len = g[node].size();
  for (int i = 0; i < len; i++) {
    int v = g[node][i];
    if (v == p || del[v]) continue;
    dfs(v, node);
    subtree[node] += subtree[v];
  }
}
int getcenter(int node, int p) {
  int len = g[node].size();
  for (int i = 0; i < len; i++) {
    int v = g[node][i];
    if (v == p || del[v]) continue;
    if (subtree[v] > tot / 2) return getcenter(v, node);
  }
  return node;
}
long long ans = 0;
void Qry(int node, int p, int val = 0) {
  val ^= a[node];
  for (int i = 0; i <= 25; i++) {
    if (val & (1 << i)) {
      ans += (now - bit[i]) * 1LL * (1LL << i);
    } else
      ans += (bit[i] * 1LL * (1LL << i));
  }
  int len = g[node].size();
  for (int i = 0; i < len; i++) {
    int v = g[node][i];
    if (v == p || del[v]) continue;
    Qry(v, node, val);
  }
}
void update(int node, int p, int val) {
  val ^= a[node];
  now++;
  ans += val;
  for (int i = 0; i <= 25; i++) {
    if (val & (1 << i)) bit[i]++;
  }
  int len = g[node].size();
  for (int i = 0; i < len; i++) {
    int v = g[node][i];
    if (v == p || del[v]) continue;
    update(v, node, val);
  }
}
void decompose(int node, int p) {
  memset(bit, 0, sizeof bit);
  now = 0;
  tot = 0;
  dfs(node, p);
  int center = getcenter(node, p);
  for (int i = 0; i < g[center].size(); i++) {
    int v = g[center][i];
    if (v == p || del[v]) continue;
    Qry(v, center);
    update(v, center, a[center]);
  }
  par[center] = p;
  del[center] = 1;
  for (int i = 0; i < g[center].size(); i++) {
    int v = g[center][i];
    if (v == p || del[v]) continue;
    decompose(v, center);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  decompose(1, -1);
  for (int i = 1; i <= n; i++) ans += a[i];
  cout << ans << endl;
}
