#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010];
int n, a[100010], d[100010];
long long res, cntBit[100010][20][3], F[100010][20][3];
int getbit(int x, int i) { return ((x >> i) & 1); }
void findway(int u, int pa) {
  for (int i = 0; i < 20; i++) cntBit[u][i][getbit(d[u], i)]++;
  for (int j = 0; j < adj[u].size(); j++) {
    int v = adj[u][j];
    if (v != pa) {
      d[v] = d[u] ^ a[v];
      findway(v, u);
      for (int i = 0; i < 20; i++)
        for (int x = 0; x < 2; x++)
          for (int y = 0; y < 2; y++)
            F[u][i][x ^ y] += 1ll * cntBit[u][i][x] * cntBit[v][i][y];
      for (int i = 0; i < 20; i++)
        for (int x = 0; x < 2; x++) cntBit[u][i][x] += cntBit[v][i][x];
    }
  }
  for (int i = 0; i < 20; i++)
    res += 1ll * F[u][i][getbit(a[u], i) ^ 1] * (1ll << i);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> 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);
  }
  d[1] = a[1];
  res = 0;
  findway(1, -1);
  for (int i = 1; i <= n; i++) res += a[i];
  cout << res << endl;
}
