#include <bits/stdc++.h>
using namespace std;
long long dp[100010][22][2], ans, v[100010];
int k;
vector<int> g[100010];
void dfs(int at, int pai) {
  for (int i = 0; i < 22; i++) dp[at][i][(v[at] >> i) & 1] = 1;
  for (int x : g[at])
    if (x != pai) dfs(x, at);
  for (int x : g[at]) {
    if (x == pai) continue;
    for (int i = 0; i < 22; i++)
      ans += (dp[at][i][0] * dp[x][i][1]) * (1 << i),
          ans += (dp[at][i][1] * dp[x][i][0]) * (1 << i);
    for (int i = 0; i < 22; i++)
      dp[at][i][0 ^ ((v[at] >> i) & 1)] += dp[x][i][0],
          dp[at][i][1 ^ ((v[at] >> i) & 1)] += dp[x][i][1];
  }
}
int main() {
  int i, n, a, b;
  scanf("%d", &n);
  ans = 0;
  for (i = 1; i <= n; i++) scanf("%d", &v[i]), ans += v[i];
  for (i = 0; i < n - 1; i++)
    scanf("%d%d", &a, &b), g[a].push_back(b), g[b].push_back(a);
  dfs(1, 1);
  printf("%lld\n", ans);
}
