#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 7;
int a[MAXN], b[MAXN];
int dp[MAXN][2];
vector<int> link[MAXN];
long long sum = 0;
void dfs(int u, int pre = -1) {
  dp[u][0] = dp[u][1] = 0;
  dp[u][b[u]]++;
  for (int i = 0; i < link[u].size(); ++i) {
    int v = link[u][i];
    if (v != pre) {
      dfs(v, u);
      sum += dp[v][0] * dp[u][1] + dp[v][1] * dp[u][0];
      dp[u][b[u]] += dp[v][0];
      dp[u][b[u] ^ 1] += dp[v][1];
    }
  }
  sum += b[u];
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= n; ++i) link[i].clear();
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    int u, v;
    for (int i = 1; i < n; ++i) {
      scanf("%d %d", &u, &v);
      link[u].push_back(v);
      link[v].push_back(u);
    }
    long long ans = 0;
    for (int i = 0; i <= 20; ++i) {
      sum = 0;
      for (int j = 1; j <= n; ++j) {
        if (a[j] & (1 << i)) {
          b[j] = 1;
        } else {
          b[j] = 0;
        }
      }
      dfs(1);
      ans += (sum << i);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
