#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, arr[100001];
int val[100001];
vector<int> adj[100001];
long long ans = 0, cur;
long long dp[100001][2];
void dfs(int node, int par) {
  dp[node][0] = (val[node] == 0);
  dp[node][1] = (val[node] == 1);
  for (int x : adj[node])
    if (x != par) {
      dfs(x, node);
      ans += cur * (dp[node][0] * dp[x][1] + dp[node][1] * dp[x][0]);
      if (val[node] == 0) {
        dp[node][0] += dp[x][0];
        dp[node][1] += dp[x][1];
      } else {
        dp[node][0] += dp[x][1];
        dp[node][1] += dp[x][0];
      }
    }
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> arr[i];
    ans += arr[i];
  }
  for (int i = 0; i + 1 < N; i++) {
    int X, Y;
    cin >> X >> Y;
    adj[X].push_back(Y);
    adj[Y].push_back(X);
  }
  for (int i = 0; i < 20; i++) {
    cur = (1 << i);
    for (int j = 1; j <= N; j++)
      if (((1 << i) & arr[j]) == 0)
        val[j] = 0;
      else
        val[j] = 1;
    dfs(1, 1);
  }
  cout << ans << endl;
  return 0;
}
