#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  if (a == 0) return 0;
  if (a == 1 || n == 0) return 1;
  if (n == 1) return a % 1000000007;
  long long t = power(a, n / 2);
  t = t * t % 1000000007;
  if (n & 1) return t * a % 1000000007;
  return t;
}
int popcount(long long a) {
  int c = 0;
  while (a) {
    c++;
    a -= a & -a;
  }
  return c;
}
void factorize(int a) {}
void update(int tree[], int idx, int val, int maxval) {
  for (; idx <= maxval; idx += idx & -idx) {
    tree[idx] += val;
  }
}
int read(int tree[], int idx) {
  long long sum = 0;
  for (; idx > 0; idx -= idx & -idx) {
    sum += tree[idx];
  }
  return sum;
}
struct node2 {
  int id, val;
  node2() {
    static int ctx = 1;
    id = ctx++;
  };
  node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
    val = a;
  }
};
struct comp2 {
  bool operator()(int a, int b) { return b < a; }
};
bool cmp2(int a, int b) { return b < a; }
struct node {
  int id, val;
  node() {
    static int ctx = 1;
    id = ctx++;
  };
  node(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
    val = a;
  }
};
struct comp {
  bool operator()(int a, int b) { return b < a; }
};
bool cmp(int a, int b) { return b < a; }
int n, m, a[100009], b, c, d, k, h, w, x, y, p, q, t, res, ma, mi, T,
    act = 0, pas = 1, cur, flag, now;
int bit[33][100009];
long long ans, dp[100009][2];
char s[1];
double e, f, z;
vector<int> v[100009], vec;
set<int> sett;
map<int, int> mapp;
void print() {}
void print2() {}
void input() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
}
void init() {
  for (int pos = 0; pos < 30; pos++) {
    for (int i = 1; i < n + 1; i++) {
      bit[pos][i] = (((1 << pos) & a[i]) != 0);
    }
  }
}
void calc(int id, int par, int a[]) {
  dp[id][a[id]] = 1;
  for (auto u : v[id]) {
    if (u == par) continue;
    calc(u, id, a);
    if (a[id]) {
      dp[id][1] += dp[u][0];
      dp[id][0] += dp[u][1];
      ans += T * (dp[id][1] - dp[u][0]) * dp[u][0];
      ans += T * (dp[id][0] - dp[u][1]) * dp[u][1];
    } else {
      dp[id][1] += dp[u][1];
      dp[id][0] += dp[u][0];
      ans += T * (dp[id][1] - dp[u][1]) * dp[u][0];
      ans += T * (dp[id][0] - dp[u][0]) * dp[u][1];
    }
  }
  ans += T * a[id];
}
void solve() {
  init();
  int l = 0;
  int r = 29;
  for (int pos = l; pos < r + 1; pos++) {
    T = 1 << pos;
    memset(dp, 0, sizeof(dp));
    calc(1, 0, bit[pos]);
  }
}
void output() { cout << ans; }
int main() {
  input();
  solve();
  output();
  return 0;
}
