#include <bits/stdc++.h>
using namespace std;
int n, col[234567], rp[234567];
vector<int> al[234567], al2[234567];
int fndr(int a) { return rp[a] = (a == rp[a] ? a : fndr(rp[a])); }
queue<int> q;
int dst[234567], s[234567];
void psh(int a, int d) {
  if (!s[a]) {
    s[a] = 1;
    dst[a] = d;
    q.push(a);
  }
}
pair<int, int> go(int st) {
  psh(st, 0);
  while (!q.empty()) {
    int at = q.front();
    q.pop();
    for (int to : al2[at]) psh(to, dst[at] + 1);
  }
  int bst = -1, bid;
  for (int i = (0); i < (n); i++)
    if (fndr(i) == i && dst[i] > bst) bst = dst[i], bid = i;
  for (int i = (0); i < (n); i++) s[i] = 0;
  return {bst, bid};
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d", col + i);
  for (int i = (0); i < (n); i++) rp[i] = i;
  for (int i = (0); i < (n - 1); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    al[u].push_back(v);
    al[v].push_back(u);
    if (col[u] == col[v]) rp[fndr(u)] = fndr(v);
  }
  for (int i = (0); i < (n); i++)
    for (int to : al[i]) {
      int a = fndr(i), b = fndr(to);
      if (a != b) al2[a].push_back(b), al2[b].push_back(a);
    }
  int st = 0;
  while (fndr(st) != st) st++;
  st = go(st).second;
  printf("%d\n", (go(st).first + 1) / 2);
  return 0;
}
