#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF = 1e9 + 7;
int n;
int a[N];
int cur[N];
vector<int> g[N];
long long ans;
long long p[N][2][22];
void dfs(int v, int pr) {
  if (pr && int(g[v].size()) == 1) {
    for (int i = 0; i <= 21; i++) {
      if ((a[v] & (1 << i)))
        p[v][1][i]++;
      else
        p[v][0][i]++;
    }
    return;
  }
  long long cur[2][22];
  for (int i = 0; i <= 21; i++) {
    cur[1][i] = 0;
    cur[0][i] = 0;
  }
  for (auto to : g[v]) {
    if (to == pr) continue;
    dfs(to, v);
    for (int i = 0; i <= 21; i++) {
      if ((a[v] & (1 << i))) {
        ans += (cur[1][i] * 1LL * p[to][1][i]) * 1LL * (1 << i);
        ans += (cur[0][i] * 1LL * p[to][0][i]) * 1LL * (1 << i);
        ans += p[to][0][i] * 1LL * (1 << i);
      } else {
        ans += p[to][1][i] * 1LL * (1 << i);
        ans += (cur[1][i] * 1LL * p[to][0][i]) * 1LL * (1 << i);
        ans += (cur[0][i] * 1LL * p[to][1][i]) * 1LL * (1 << i);
      }
      cur[1][i] += p[to][1][i];
      cur[0][i] += p[to][0][i];
    }
  }
  for (int i = 0; i <= 21; i++) {
    if ((a[v] & (1 << i))) {
      p[v][1][i] = cur[0][i];
      p[v][0][i] = cur[1][i];
      p[v][1][i]++;
    } else {
      p[v][1][i] = cur[1][i];
      p[v][0][i] = cur[0][i];
      p[v][0][i]++;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ans += a[i] * 1LL;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans;
  return 0;
}
