#include <bits/stdc++.h>
using namespace std;
const long long _N = 1e5 + 11;
const long long INF = 1e18 + 11;
const long long MOD = 1e9 + 7;
const double EPS = 1e-7;
struct Node {
  pair<long long, long long> c[22], ch[22], sum[22];
  Node() {
    for (long long i = 0; i < 22; i++) {
      c[i].first = 0;
      c[i].second = 0;
      ch[i].first = 0;
      ch[i].second = 0;
      sum[i].first = 0;
      sum[i].second = 0;
    }
  }
} node[_N];
long long n, a[_N];
vector<long long> adj[_N];
void dfs(long long v, long long p) {
  for (long long i = 0; i < 20; i++) {
    if (a[v] & (1 << i)) {
      node[v].c[i].first += 1;
      node[v].sum[i].first += 1;
    } else {
      node[v].c[i].second += 1;
      node[v].sum[i].second += 1;
    }
  }
  for (auto x : adj[v]) {
    if (x == p) continue;
    dfs(x, v);
    for (long long i = 0; i < 20; i++) {
      node[v].ch[i].first += node[x].c[i].first;
      node[v].ch[i].second += node[x].c[i].second;
      if (a[v] & (1 << i)) {
        node[v].c[i].first += node[x].c[i].second;
        node[v].c[i].second += node[x].c[i].first;
        node[v].sum[i].first += node[x].c[i].second;
        node[v].sum[i].second += node[x].c[i].first;
      } else {
        node[v].c[i].first += node[x].c[i].first;
        node[v].c[i].second += node[x].c[i].second;
        node[v].sum[i].first += node[x].c[i].first;
        node[v].sum[i].second += node[x].c[i].second;
      }
    }
  }
  for (auto x : adj[v]) {
    if (x == p) continue;
    for (long long i = 0; i < 20; i++) {
      node[v].ch[i].first -= node[x].c[i].first;
      node[v].ch[i].second -= node[x].c[i].second;
      if (a[v] & (1 << i)) {
        node[v].sum[i].first += (node[x].c[i].second * node[v].ch[i].second +
                                 node[x].c[i].first * node[v].ch[i].first);
        node[v].sum[i].second += (node[x].c[i].first * node[v].ch[i].second +
                                  node[x].c[i].second * node[v].ch[i].first);
      } else {
        node[v].sum[i].first += (node[x].c[i].first * node[v].ch[i].second +
                                 node[x].c[i].second * node[v].ch[i].first);
        node[v].sum[i].second += (node[x].c[i].second * node[v].ch[i].second +
                                  node[x].c[i].first * node[v].ch[i].first);
      }
      node[v].sum[i].first += node[x].sum[i].first;
      node[v].sum[i].second += node[x].sum[i].second;
    }
  }
}
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cout << fixed;
  cout << setprecision(15);
  srand(time(NULL));
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  long long res = 0;
  for (long long i = 0; i < 20; i++) {
    res += node[1].sum[i].first * (1 << i);
  }
  cout << res << '\n';
  return 0;
}
