#include <bits/stdc++.h>
using namespace std;
int c[223456];
vector<int> g1[223456], g2[223456];
void dfs1(int p, int x, int cm) {
  for (auto i : g1[x]) {
    if (i == p) continue;
    if (c[i] == c[x]) {
      dfs1(x, i, cm);
    } else {
      g2[cm].push_back(i);
      g2[i].push_back(cm);
      dfs1(x, i, i);
    }
  }
}
int ff, xx = -1;
void dfs2(int p, int x, int d) {
  if (xx < d) xx = d, ff = x;
  for (auto i : g2[x]) {
    if (p == i) continue;
    dfs2(x, i, d + 1);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    --y;
    --x;
    g1[x].push_back(y);
    g1[y].push_back(x);
  }
  dfs1(0, 0, 0);
  dfs2(0, 0, 0);
  xx = -1;
  dfs2(ff, ff, 0);
  printf("%d\n", (xx + 1) / 2);
}
