#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e9 + 7, M = 20;
long long n, k, i, j;
long long A[N], dp[N][M][2];
bitset<M> bit[N];
vector<long long> adj[N];
long long dfs(long long cur, long long p) {
  for (i = 0; i < M; i++) dp[cur][i][bit[cur][i]] = 1;
  long long ans = A[cur], temp;
  for (auto i : adj[cur])
    if (i != p) {
      ans += dfs(i, cur);
      for (j = 0; j < M; j++) {
        temp = dp[cur][j][0] * dp[i][j][1] + dp[cur][j][1] * dp[i][j][0];
        ans += temp * (1 << j);
        dp[cur][j][0] += dp[i][j][bit[cur][j]];
        dp[cur][j][1] += dp[i][j][!bit[cur][j]];
      }
    }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, a, b, ans = 0;
  cin >> n;
  for (i = 1; i < n + 1; i++) {
    cin >> A[i];
    a = A[i];
    for (j = 0; j < M; j++) bit[i][j] = a & 1, a >>= 1;
  }
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
  }
  cout << dfs(1, 1);
}
