#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100007], sum1, res, num[100007][2];
vector<int> E[100007];
void dfs(int x, int f, int bit) {
  int t = (a[x] >> bit) & 1;
  num[x][t] = 1, num[x][t ^ 1] = 0;
  long long s = 0;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (v == f) continue;
    dfs(v, x, bit);
    s += num[x][0] * num[v][1] + num[x][1] * num[v][0];
    num[x][t ^ 0] += num[v][0];
    num[x][t ^ 1] += num[v][1];
  }
  res += s << bit;
}
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d\n", &a[i]), sum1 += a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    E[x].push_back(y);
    E[y].push_back(x);
  }
  for (int i = 0; i < 30; i++) dfs(1, 0, i);
  printf("%I64d\n", res + sum1);
}
