#include <bits/stdc++.h>
using namespace std;
const long long Max = 1e5 + 2;
vector<long long> adj[Max];
long long memo[2][Max];
long long value[Max];
long long sum;
void dfs(long long node, long long par, long long bit) {
  bool currValue = ((value[node] & (1 << bit)) > 0);
  memo[0][node] = 0;
  memo[1][node] = 0;
  for (long long to : adj[node]) {
    if (to == par) continue;
    dfs(to, node, bit);
    sum += memo[1][to] * memo[0][node];
    sum += memo[0][to] * memo[1][node];
    memo[0 ^ currValue][node] += memo[0][to];
    memo[1 ^ currValue][node] += memo[1][to];
  }
  memo[currValue][node]++;
  sum += memo[1][node];
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long sumValues = 0;
  for (long long i = 1; i <= n; ++i) {
    cin >> value[i];
    sumValues += value[i];
  }
  long long a, b;
  for (long long i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long res = 0;
  for (long long i = 0; i <= 20; ++i) {
    sum = 0;
    dfs(1, 1, i);
    res += sum * (1 << i);
  }
  cout << res << '\n';
  return 0;
}
