#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
unsigned long long A[N], O[N][20], E[N][20], ans = 0;
vector<int> G[N];
void dfs(int u, int p) {
  for (int v : G[u])
    if (v != p) dfs(v, u);
  for (int i = 0; i < int(20); i++) {
    for (int v : G[u]) {
      if (A[u] & (1 << i)) {
        O[u][i] += E[v][i];
        E[u][i] += O[v][i];
      } else {
        O[u][i] += O[v][i];
        E[u][i] += E[v][i];
      }
    }
    if (A[u] & (1 << i))
      O[u][i]++;
    else
      E[u][i]++;
  }
}
void solve(int u, int p) {
  for (int v : G[u]) {
    if (v == p) continue;
    for (int i = 0; i < int(20); i++) {
      if (A[u] & (1 << i)) {
        O[u][i] -= E[v][i];
        E[u][i] -= O[v][i];
      } else {
        O[u][i] -= O[v][i];
        E[u][i] -= E[v][i];
      }
      ans += (1 << i) * (O[v][i] * E[u][i] + E[v][i] * O[u][i]);
    }
  }
  for (int v : G[u])
    if (v != p) solve(v, u);
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i < int(n + 1); i++) cin >> A[i];
  for (int i = 0; i < int(n - 1); i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i < int(n + 1); i++) ans += A[i];
  solve(1, 0);
  cout << ans << endl;
  return 0;
}
