#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
vector<long long> grafo[MAXN];
long long v[MAXN];
bool process[MAXN];
long long pot[30];
struct str {
  long long first, second, tot = 0;
};
str dfs(long long x, long long k) {
  process[x] = true;
  long long val = v[x] & pot[k];
  str resp;
  resp.first = resp.second = resp.tot = 0;
  if (x != 1 && grafo[x].size() == 1) {
    if (val == 0)
      resp.first = 1;
    else
      resp.second += 1, resp.tot += 1;
    return resp;
  }
  long long tot1 = 0, tot0 = 0;
  long long total = 0;
  vector<str> vec;
  for (long long i = 0; i < grafo[x].size(); i++) {
    long long at = grafo[x][i];
    if (process[at] == true) continue;
    str z = dfs(at, k);
    resp.tot += z.tot;
    vec.push_back(z);
    tot1 += z.second;
    tot0 += z.first;
    if (val == 0)
      resp.first += z.first, resp.second += z.second;
    else
      resp.first += z.second, resp.second += z.first;
  }
  if (val == 0) {
    for (long long i = 0; i < vec.size(); i++) {
      str at = vec[i];
      total += at.first * (tot1 - at.second) + at.second * (tot0 - at.first);
    }
  } else {
    for (long long i = 0; i < vec.size(); i++) {
      str at = vec[i];
      total += at.first * (tot0 - at.first) + at.second * (tot1 - at.second);
    }
  }
  total /= 2;
  resp.tot += total;
  if (val == 0)
    resp.tot += tot1;
  else
    resp.tot += tot0;
  if (val == 0)
    resp.first += 1;
  else
    resp.second += 1, resp.tot += 1;
  return resp;
}
signed main() {
  memset(process, false, sizeof process);
  long long n;
  cin >> n;
  long long soma = 0;
  long long p = 1;
  for (long long i = 0; i <= 25; i++) {
    pot[i] = p;
    p *= 2;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
    soma += v[i];
  }
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    grafo[x].push_back(y);
    grafo[y].push_back(x);
  }
  long long r = 0;
  for (long long i = 0; i <= 22; i++) {
    memset(process, false, sizeof process);
    r += pot[i] * dfs(1, i).tot;
  }
  cout << r << endl;
}
