#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 1e5 + 100;
int n, a[N], bit;
long long ans = 0, cnt[N][2];
vector<int> G[N];
void dfs(int x, int fa) {
  int t = (a[x] >> bit) & 1;
  cnt[x][t] = 1, cnt[x][1 - t] = 0;
  for (int y : G[x]) {
    if (y == fa) continue;
    dfs(y, x);
    ans += ((cnt[x][0] * cnt[y][1] + cnt[x][1] * cnt[y][0]) << bit);
    cnt[x][t ^ 1] += cnt[y][1];
    cnt[x][t ^ 0] += cnt[y][0];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d", &x), scanf("%d", &y);
    G[x].push_back(y), G[y].push_back(x);
  }
  for (bit = 0; bit <= 22; bit++) dfs(1, 0);
  printf("%lld\n", ans);
  return 0;
}
