#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
struct node {
  int next, to;
} e[2 * N];
int head[N], tot = 0, dis[N], a[N], n;
void add(int x, int y) {
  e[++tot].next = head[x];
  head[x] = tot;
  e[tot].to = y;
}
void dfs(int x, int f) {
  int i, y;
  for (i = head[x]; i; i = e[i].next)
    if ((y = e[i].to) != f) {
      dis[y] = dis[x] + (a[x] ^ a[y]);
      dfs(y, x);
    }
}
int main() {
  int i, j, k, mx, p, x, y;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dis[1] = 1;
  dfs(1, 0);
  mx = -1;
  p = 0;
  for (i = 1; i <= n; i++)
    if (dis[i] > mx) mx = dis[i], p = i;
  dis[p] = 1;
  dfs(p, 0);
  mx = -1;
  for (i = 1; i <= n; i++) mx = max(mx, dis[i]);
  printf("%d\n", mx / 2);
  return 0;
}
