#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
int n;
const int nax = 1e5 + 5;
int a[nax];
int dp[nax][2];
long long res = 0;
int k;
void dfs(int v, int p = -1) {
  dp[v][0] = 0;
  dp[v][1] = 0;
  for (auto &c : adj[v]) {
    if (c == p) continue;
    dfs(c, v);
    res += (1LL * (dp[c][0] * dp[v][1] + dp[c][1] * dp[v][0]));
    if (a[v] & (1 << k)) {
      dp[v][0] += dp[c][1];
      dp[v][1] += dp[c][0];
    } else {
      dp[v][0] += dp[c][0];
      dp[v][1] += dp[c][1];
    }
  }
  dp[v][(a[v] & (1 << k)) ? 1 : 0]++;
  res += (long long)dp[v][1];
}
void solve() {
  cin >> n;
  adj.resize(n + 1);
  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);
  }
  long long ans = 0;
  for (k = 19; k >= 0; --k) {
    res = 0;
    dfs(1);
    ans += res << k;
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
