#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4611686018427387903;
const int Sz = 2e5 + 1;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
}
int n;
int a[Sz];
long long dp[Sz][20][2], lca[Sz][20][2], sum[Sz][20][2];
vector<int> g[Sz];
void dfs(int v, int pr) {
  for (int i = 0; i < 20; i++) dp[v][i][((a[v] & (1 << i)) > 0)]++;
  for (auto to : g[v]) {
    if (to != pr) {
      dfs(to, v);
      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 2; j++) {
          bool bit = (a[v] & (1 << i)) > 0;
          bool b = (j ^ bit);
          dp[v][i][b] += dp[to][i][j];
        }
      }
    }
  }
  for (auto to : g[v]) {
    if (to != pr) {
      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 2; j++) {
          for (int k = 0; k < 2; k++) {
            bool bit = (a[v] & (1 << i)) > 0;
            bool b = (j ^ k ^ bit);
            lca[v][i][b] += sum[v][i][j] * dp[to][i][k];
          }
        }
        for (int j = 0; j < 2; j++) sum[v][i][j] = sum[v][i][j] + dp[to][i][j];
      }
    }
  }
}
int main() {
  Read_rap();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 1);
  long long ans = 0;
  for (int i = 0; i < 20; i++)
    for (int v = 1; v <= n; v++)
      ans = (ans + (dp[v][i][1] + lca[v][i][1]) * (1ll << i));
  cout << ans;
  return 0;
}
