#include <bits/stdc++.h>
using namespace std;
vector<int> graph[200000];
int color[200000], black, white, maxDist, farNode;
void solve(int node, int par, int dis) {
  if (dis > maxDist) farNode = node, maxDist = dis;
  for (auto &v : graph[node]) {
    if (v == par) continue;
    solve(v, node, dis + (color[node] != color[v]));
  }
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie();
  int n, a, b, firstNode;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> color[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  solve(0, -1, 1);
  maxDist = 1;
  solve(farNode, -1, 1);
  cout << (maxDist) / 2;
  return 0;
}
