#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 123;
int a[N];
vector<int> g[N];
int n, node, stdist = 0;
void dfs(int k, int par, int dist) {
  if (dist > stdist) {
    node = k;
    stdist = dist;
  }
  for (auto it : g[k]) {
    if (it == par) continue;
    dfs(it, k, dist + (a[k] ^ a[it]));
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  node = 1;
  dfs(node, node, 0);
  dfs(node, node, 0);
  cout << (stdist + 1) / 2;
  return false;
}
