#include <bits/stdc++.h>
using namespace std;
const int maxn = 100123;
const int lgn = 20;
long long a[maxn], f[maxn][lgn], ans;
vector<int> G[maxn];
void dfs(int u, int p, int x) {
  int w = a[u] >> x & 1;
  f[u][w] = 1, f[u][w ^ 1] = 0;
  for (auto& v : G[u]) {
    if (v != p) {
      dfs(v, u, x);
      ans += (1 << x) * (f[u][1] * f[v][0] + f[u][0] * f[v][1]);
      f[u][w] += f[v][0];
      f[u][w ^ 1] += f[v][1];
    }
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) cin >> a[i], ans += a[i];
  for (int i = 0; i < (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i < (lgn); ++i) dfs(0, -1, i);
  cout << ans << '\n';
}
