#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;
const int LIM = 1e5 + 5;
ll dp[LIM][4];
void solve(vector<vector<int>> &g, int u, int v, int a[], int bit) {
  bool flag = (a[u] >> bit) & 1;
  vector<array<ll, 2>> child;
  ll even = 0, odd = 0;
  for (auto x : g[u]) {
    if (x == v) continue;
    solve(g, x, u, a, bit);
    dp[u][0] += dp[x][0];
    dp[u][1] += dp[x][1];
    dp[u][2] += dp[x][2 ^ flag];
    dp[u][3] += dp[x][3 ^ flag];
    child.push_back({dp[x][2], dp[x][3]});
    even += dp[x][2];
    odd += dp[x][3];
  }
  dp[u][flag ^ 2]++;
  dp[u][0] += dp[u][2];
  dp[u][1] += dp[u][3];
  ll add1 = 0, add2 = 0;
  for (auto [e, o] : child) {
    add1 += (even - e) * o + (odd - o) * e;
    add2 += (even - e) * e + (odd - o) * o;
  }
  dp[u][flag ^ 1] += add1 / 2;
  dp[u][flag] += add2 / 2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    g[--v].push_back(--u);
    g[u].push_back(v);
  }
  ll ans = 0;
  for (int bit = 19; bit >= 0; --bit) {
    memset(dp, 0, sizeof dp);
    solve(g, 0, -1, a, bit);
    ans += (1LL << bit) * dp[0][1];
  }
  cout << ans;
}
