#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
using ll = long long;
vector<int> edges[maxn];
ll ans[30];
ll dp[maxn][30][2];
int a[maxn];
void dfs(int x, int p) {
  for (auto i : edges[x]) {
    if (i != p) {
      dfs(i, x);
      for (int j = 0; j <= 20; ++j) {
        ans[j] += dp[x][j][0] * dp[i][j][1];
        ans[j] += dp[x][j][1] * dp[i][j][0];
        if ((a[x] >> j) & 1) {
          dp[x][j][1] += dp[i][j][0];
          dp[x][j][0] += dp[i][j][1];
        } else {
          dp[x][j][1] += dp[i][j][1];
          dp[x][j][0] += dp[i][j][0];
        }
      }
    }
  }
  for (int i = 0; i <= 20; ++i) {
    dp[x][i][(a[x] >> i) & 1]++;
  }
  for (int i = 0; i <= 20; ++i) {
    ans[i] += dp[x][i][1];
  }
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  dfs(1, 1);
  ll res = 0;
  for (int i = 0; i <= 20; ++i) {
    res += (1LL << i) * ans[i];
  }
  cout << res << endl;
  return 0;
}
