#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long dp[maxn][2], a[maxn];
long long ans = 0;
vector<int> G[maxn];
void dfs(int x, int fa, int bit) {
  long long q = 0;
  int b = (a[x] >> bit) & 1;
  dp[x][b] = 1;
  dp[x][b ^ 1] = 0;
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i];
    if (v == fa) continue;
    dfs(v, x, bit);
    q += dp[x][0] * dp[v][1] + dp[x][1] * dp[v][0];
    dp[x][b ^ 0] += dp[v][0];
    dp[x][b ^ 1] += dp[v][1];
  }
  ans += (q << bit);
}
int main() {
  int n, u, v;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i <= 20; i++) dfs(1, 0, i);
  cout << ans << endl;
}
