#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 11;
int n, a[N];
long long dp[N][21], nRoads[N];
vector<int> f[N];
void dfs(int u, int pa) {
  for (int i = 0; i <= 20; ++i) {
    dp[u][i] = (1 & ((a[u]) >> (i)));
  }
  nRoads[u] = 1;
  for (int v : f[u]) {
    if (v == pa) continue;
    dfs(v, u);
    nRoads[u] += nRoads[v];
    for (int i = 0; i <= 20; ++i) {
      if (!(1 & ((a[u]) >> (i))))
        dp[u][i] += dp[v][i];
      else
        dp[u][i] += nRoads[v] - dp[v][i];
    }
  }
}
long long res = 0;
void calc(int u, int pa, vector<long long> f1, long long cnt) {
  for (int i = 0; i <= 20; ++i) {
    res += (f1[i] + dp[u][i] + (1 & ((a[u]) >> (i)))) * (1 << i);
  }
  for (int v : f[u]) {
    if (v == pa) continue;
    vector<long long> nf1 = f1;
    long long tmp = cnt + nRoads[u] - nRoads[v];
    for (int i = 0; i <= 20; ++i) {
      if (!(1 & ((a[u]) >> (i))))
        nf1[i] += dp[u][i] - dp[v][i];
      else
        nf1[i] += dp[u][i] - (nRoads[v] - dp[v][i]);
      if ((1 & ((a[v]) >> (i)))) nf1[i] = tmp - nf1[i];
    }
    calc(v, u, nf1, tmp);
  }
}
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    f[u].push_back(v), f[v].push_back(u);
  }
  dfs(1, -1);
  vector<long long> f(21, 0);
  calc(1, -1, f, 0);
  cout << res / 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
