#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
int arr[N];
vector<int> G[N];
long long ans = 0;
pair<int, int> dfs(int, int, int);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i <= 20; i++) dfs(1, 1, i);
  cout << ans << '\n';
  return 0;
}
pair<int, int> dfs(int w, int f, int d) {
  pair<int, int> ret = {0, 0};
  for (auto i : G[w]) {
    if (i == f) continue;
    pair<int, int> sub = dfs(i, w, d);
    if (arr[w] & (1 << d)) {
      ans += (long long)(ret.first * sub.first) << d;
      ans += (long long)(ret.second * sub.second) << d;
    } else {
      ans += (long long)(ret.second * sub.first) << d;
      ans += (long long)(ret.first * sub.second) << d;
    }
    ret.first += sub.first;
    ret.second += sub.second;
  }
  ret.first++;
  if (arr[w] & (1 << d)) swap(ret.first, ret.second);
  ans += (long long)ret.second << d;
  return ret;
}
