#include <bits/stdc++.h>
using namespace std;
int wt[100010];
vector<int> adjList[100010];
long long ret;
long long one[100010];
long long zero[100010];
void dp(int node, int b, int p = -1) {
  one[node] = zero[node] = 0;
  bool on = wt[node] & (1 << b);
  if (on)
    one[node]++;
  else
    zero[node]++;
  long long zeroes = 0;
  long long ones = 0;
  for (int i = 0; i < adjList[node].size(); i++) {
    int nxt = adjList[node][i];
    if (nxt == p) continue;
    dp(nxt, b, node);
    if (on) {
      zero[node] += one[nxt];
      one[node] += zero[nxt];
    } else {
      zero[node] += zero[nxt];
      one[node] += one[nxt];
    }
    if (zero[nxt] != 0) zeroes += zero[nxt];
    if (one[nxt] != 0) ones += one[nxt];
  }
  int mul = (1 << b);
  if (on) {
    ret += mul * (one[node] - 1);
  } else
    ret += mul * one[node];
  for (int i = 0; i < adjList[node].size(); i++) {
    int nxt = adjList[node][i];
    if (nxt == p) continue;
    if (zero[nxt] != 0) {
      zeroes -= zero[nxt];
    }
    if (one[nxt] != 0) {
      ones -= one[nxt];
    }
    if (on) {
      ret += mul * zero[nxt] * zeroes;
      ret += mul * one[nxt] * ones;
    } else {
      ret += mul * ones * zero[nxt];
      ret += mul * zeroes * one[nxt];
    }
  }
}
int main(void) {
  int n;
  scanf("%d", &n);
  ret = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &wt[i]);
    ret += wt[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int fr, to;
    scanf("%d", &fr);
    scanf("%d", &to);
    fr--, to--;
    adjList[fr].push_back(to);
    adjList[to].push_back(fr);
  }
  for (int i = 0; i <= 22; i++) {
    memset(one, 0, sizeof(one));
    memset(zero, 0, sizeof(zero));
    dp(0, i);
  }
  cout << ret;
  return 0;
}
