#include <bits/stdc++.h>
using namespace std;
int i, n, a[100005], x, y;
long long rs, dp[2][20][100005];
vector<int> lda[100005];
void dfs(int x, int tata) {
  for (int i = 0; i < 20; ++i) dp[(a[x] >> i) & 1][i][x] = 1;
  for (auto it : lda[x]) {
    if (it == tata) continue;
    dfs(it, x);
    for (int i = 0; i < 20; ++i)
      rs += (1LL << i) *
            (dp[0][i][x] * dp[1][i][it] + dp[1][i][x] * dp[0][i][it]);
    for (int i = 0; i < 20; ++i) {
      dp[((a[x] >> i) & 1)][i][x] += dp[0][i][it];
      dp[1 - ((a[x] >> i) & 1)][i][x] += dp[1][i][it];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> a[i], rs += a[i];
  for (i = 1; i < n; ++i) {
    cin >> x >> y;
    lda[x].push_back(y);
    lda[y].push_back(x);
  }
  dfs(1, 1);
  cout << rs << '\n';
  return 0;
}
