#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1LL;
  long long int p = power(a, b / 2);
  p = p * p;
  return (b & 1) ? p * a : p;
}
const int N = 1e5 + 6;
long long int n, a[N], dp[N][21][2], ans = 0;
vector<vector<int> > adj(N);
void dfs(int u, int p) {
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    long long int dp2[21][2];
    for (int i = 0; i < 21; i++)
      dp2[i][1] = dp[u][i][1], dp2[i][0] = dp[u][i][0];
    for (int i = 0; i < 21; i++) {
      ans += dp[v][i][0] * dp2[i][1] * (1 << i);
      ans += dp[v][i][1] * dp2[i][0] * (1 << i);
      dp[u][i][0] += (a[u] & (1 << i)) ? dp[v][i][1] : dp[v][i][0];
      dp[u][i][1] += (a[u] & (1 << i)) ? dp[v][i][0] : dp[v][i][1];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 0; j < 21; j++) {
      if (a[i] & (1 << j))
        dp[i][j][1] = 1;
      else
        dp[i][j][0] = 1;
    }
    ans += a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans << endl;
  return 0;
}
