#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
long long dp[maxn][2];
long long a[maxn];
long long ans = 0;
vector<long long> AdjList[maxn];
long long n;
void dfs(long long bit, long long s, long long p = -1) {
  dp[s][0] = dp[s][1] = 0;
  for (long long u : AdjList[s]) {
    if (u == p) continue;
    dfs(bit, u, s);
    if (a[s] & (1 << bit)) {
      ans += ((dp[s][0] * dp[u][1] + dp[s][1] * dp[u][0]) * (1 << bit));
      dp[s][0] += dp[u][1];
      dp[s][1] += dp[u][0];
    } else {
      ans += ((dp[s][0] * dp[u][1] + dp[s][1] * dp[u][0]) * (1 << bit));
      dp[s][1] += dp[u][1];
      dp[s][0] += dp[u][0];
    }
  }
  dp[s][(a[s] >> bit) & 1]++;
  ans += (dp[s][1] << bit);
}
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 u, v;
    cin >> u >> v;
    AdjList[u].push_back(v);
    AdjList[v].push_back(u);
  }
  dfs(1, -1);
  long long finale = 0;
  for (long long bit = 0; bit < 20; bit++) {
    dfs(bit, 1);
  }
  cout << ans;
}
