#include <bits/stdc++.h>
using namespace std;
long long int a[100001];
vector<long long int> adj[100001];
long long int ans[21] = {};
long long int dp[100001][21][2];
void dfs(long long int i, long long int par) {
  long long int u = 0;
  for (long long int j = 0; j < adj[i].size(); j++) {
    long long int x = adj[i][j];
    if (x != par) {
      dfs(x, i);
      if (u == 0) {
        u = 1;
        long long int z = a[i];
        for (long long int k = 0; k <= 20; k++) {
          if (z % 2) {
            dp[i][k][1] = dp[x][k][0] + 1;
            dp[i][k][0] = dp[x][k][1];
          } else {
            dp[i][k][1] = dp[x][k][1];
            dp[i][k][0] = dp[x][k][0] + 1;
          }
          z = z / 2;
          ans[k] += dp[i][k][1];
        }
      } else {
        long long int z = a[i];
        for (long long int k = 0; k <= 20; k++) {
          ans[k] += dp[i][k][1] * dp[x][k][0] + dp[i][k][0] * dp[x][k][1];
          if (z % 2) {
            dp[i][k][1] += dp[x][k][0];
            dp[i][k][0] += dp[x][k][1];
          } else {
            dp[i][k][1] += dp[x][k][1];
            dp[i][k][0] += dp[x][k][0];
          }
          z = z / 2;
        }
      }
    }
  }
  if (u == 0) {
    long long int z = a[i];
    for (long long int k = 0; k <= 20; k++) {
      if (z % 2) {
        ans[k]++;
        dp[i][k][1]++;
      } else {
        dp[i][k][0]++;
      }
      z = z / 2;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  long long int f = 1, pt = 0;
  for (long long int i = 0; i <= 20; i++) {
    pt += f * ans[i];
    f = f * 2;
  }
  cout << pt;
  return 0;
}
