#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N];
vector<int> edge[N];
long long dp[N][2];
int n;
long long DFS(int u, int fa) {
  dp[u][b[u]] = 1;
  dp[u][b[u] ^ 1] = 0;
  long long ret = b[u];
  for (int v : edge[u])
    if (v != fa) {
      ret += DFS(v, u);
      ret += dp[u][0] * dp[v][1] + dp[u][1] * dp[v][0];
      dp[u][b[u]] += dp[v][0];
      dp[u][b[u] ^ 1] += dp[v][1];
    }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 0; i <= 20; ++i) {
    for (int j = 1; j <= n; ++j) {
      b[j] = a[j] & (1 << i) ? 1 : 0;
    }
    long long sum = DFS(1, 0);
    ans += (sum << i);
  }
  printf("%I64d\n", ans);
  return 0;
}
