#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
int dp[N][22][2], val[N];
long long ans;
vector<int> ed[N];
void load() {}
void dfs(int u, int p) {
  for (int i = 0; i <= 20; ++i)
    dp[u][i][1] += (((1 << i) & val[u]) != 0),
        dp[u][i][0] += (((1 << i) & val[u]) == 0);
  for (auto v : ed[u]) {
    if (v == p) continue;
    dfs(v, u);
    for (int i = 0; i <= 20; ++i) {
      ans += 1LL * (1 << i) * dp[u][i][0] * dp[v][i][1],
          ans += 1LL * (1 << i) * dp[u][i][1] * dp[v][i][0];
      if ((1 << i) & val[u])
        dp[u][i][1] += dp[v][i][0], dp[u][i][0] += dp[v][i][1];
      else
        dp[u][i][0] += dp[v][i][0], dp[u][i][1] += dp[v][i][1];
    }
  }
  return;
}
void trungtt() {
  int n;
  scanf("%d", &n);
  ans = 0;
  for (int i = 1; i <= n; ++i) scanf("%d", &val[i]), ans += val[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    ed[u].push_back(v), ed[v].push_back(u);
  }
  dfs(1, 0);
  printf("%lld", ans);
}
int main() {
  load();
  trungtt();
  return 0;
}
