#include <bits/stdc++.h>
using namespace std;
mt19937 Rand(time(0));
const int maxn = 1e5 + 5;
const long long maxc = 1e9 + 7;
int cnt[2][maxn];
int a[maxn], b[maxn];
vector<int> adj[maxn];
int n;
long long res, ans;
void dfs(int u, int par = -1) {
  cnt[0][u] = cnt[1][u] = 0;
  cnt[b[u]][u]++;
  res += b[u];
  for (auto v : adj[u]) {
    if (v == par) continue;
    dfs(v, u);
    res += cnt[0][u] * cnt[1][v] + cnt[0][v] * cnt[1][u];
    cnt[b[u]][u] += cnt[0][v];
    cnt[b[u] ^ 1][u] += cnt[1][v];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i <= 20; i++) {
    res = 0;
    for (int u = 1; u <= n; u++) b[u] = ((a[u] >> i) & 1);
    dfs(1);
    ans += (res << i);
  }
  cout << ans;
  return 0;
}
