#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct EDGE {
  int x, y, nex;
} edge1[N << 1], edge2[N << 1];
int n, head1[N], head2[N], cnt1, cnt2, bel[N], bcnt, f[N];
bool color[N];
void add1(int x, int y) {
  edge1[++cnt1].y = y;
  edge1[cnt1].x = x;
  edge1[cnt1].nex = head1[x];
  head1[x] = cnt1;
}
void add2(int x, int y) {
  edge2[++cnt2].y = y;
  edge2[cnt2].nex = head2[x];
  head2[x] = cnt2;
}
void dfs(int x, int fa) {
  if (color[x] == color[fa])
    bel[x] = bel[fa];
  else
    bel[x] = ++bcnt;
  for (int i = head1[x]; i; i = edge1[i].nex) {
    int y = edge1[i].y;
    if (y == fa) continue;
    dfs(y, x);
  }
}
int mdep, mx;
void dfsfd(int x, int fa, int depth) {
  if (depth > mdep) {
    mdep = depth;
    mx = x;
  }
  for (int i = head2[x]; i; i = edge2[i].nex) {
    int y = edge2[i].y;
    if (y == fa) continue;
    dfsfd(y, x, depth + 1);
  }
}
int find(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = find(f[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &color[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add1(x, y), add1(y, x);
  }
  bel[1] = 1, bcnt = 1;
  dfs(1, 1);
  for (int i = 1; i <= bcnt; i++) f[i] = i;
  for (int i = 1; i <= cnt1; i++) {
    int x = edge1[i].x, y = edge1[i].y;
    if (find(bel[x]) != find(bel[y])) {
      add2(bel[x], bel[y]);
      add2(bel[y], bel[x]);
      f[find(bel[y])] = find(bel[x]);
    }
  }
  dfsfd(1, 0, 1);
  dfsfd(mx, 0, 1);
  printf("%d", mdep >> 1);
}
