#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long L = 30;
long long ans = 0;
long long n, dp[N][L], a[N], go[N][L][2];
vector<long long> g[N];
void dfs(long long v, long long p = -1) {
  for (long long i = 0; i < g[v].size(); i++)
    if (g[v][i] != p) dfs(g[v][i], v);
  for (long long b = 0; b < 27; b++) {
    dp[v][b] = 0;
    long long k0 = 1, k1 = 0;
    for (long long i = 0; i < g[v].size(); i++) {
      long long to = g[v][i];
      if (to != p) k0 += go[to][b][0], k1 += go[to][b][1];
    }
    if ((a[v] >> b) & 1) {
      go[v][b][0] = k1;
      go[v][b][1] = k0;
    } else {
      go[v][b][0] = k0;
      go[v][b][1] = k1;
    }
    for (long long i = 0; i < g[v].size(); i++) {
      long long to = g[v][i];
      if (to != p) {
        k0 -= go[to][b][0];
        k1 -= go[to][b][1];
        if ((a[v] >> b) & 1)
          dp[v][b] += go[to][b][0] * k0 + go[to][b][1] * k1;
        else
          dp[v][b] += go[to][b][0] * k1 + go[to][b][1] * k0;
      }
    }
    if ((a[v] >> b) & 1) dp[v][b]++;
    ans += dp[v][b] * (1 << b);
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1);
  cout << ans;
  return 0;
}
