#include <bits/stdc++.h>   using namespace std;   long long n, parent[100002];   long long pl[100002], ans, dp[100002][22][5];   vector<long long> gr[100002];   long long ast[65];   void dfs(long long v) {     for (long long i = 0; i <= 20; i++) {       long long x = ((pl[v] >> i) & 1);       dp[v][i][x]++;     }     long long klir[22][5];     for (long long i = 0; i <= 20; i++) {       klir[i][0] = 0;       klir[i][1] = 0;     }     for (long long i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == parent[v]) continue;       parent[gr[v][i]] = v;       dfs(gr[v][i]);       for (long long j = 0; j <= 20; j++) {         klir[j][0] += dp[gr[v][i]][j][0];         klir[j][1] += dp[gr[v][i]][j][1];       }     }     for (long long i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == parent[v]) continue;       for (long long j = 0; j <= 20; j++) {         long long x = ((pl[v] >> j) & 1);         dp[v][j][x] += dp[gr[v][i]][j][0];         dp[v][j][x ^ 1] += dp[gr[v][i]][j][1];         klir[j][0] -= dp[gr[v][i]][j][0];         klir[j][1] -= dp[gr[v][i]][j][1];         if (x == 1) {           ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][0];           ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][1];         } else {           ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][1];           ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][0];         }       }     }     for (long long i = 0; i <= 20; i++) ans += dp[v][i][1] * (ast[i]);   }   int main() {     cin >> n;     ast[0] = 1;     for (long long i = 1; i < 64; i++) ast[i] = 2 * ast[i - 1];     for (long long i = 1; i <= n; i++) scanf( %lld , &pl[i]);     for (long long i = 1; i < n; i++) {       long long k, l;       scanf( %lld%lld , &k, &l);       gr[k].push_back(l);       gr[l].push_back(k);     }     dfs(1);     cout << ans << endl;     return 0;   }   