#include <bits/stdc++.h>
using namespace std;
struct ads {
  int to, next;
} p[400010];
int n, m, sum = 0, num, s;
int head[400010], bj[400010];
int fa[400010], l[400010], r[400010];
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
inline int find(int a) {
  if (a == fa[a])
    return a;
  else
    return fa[a] = find(fa[a]);
}
inline void dfs(int a, int b, int len) {
  if (len > sum) sum = len, s = a;
  for (int i = head[a]; i; i = p[i].next)
    if (p[i].to != b) dfs(p[i].to, a, len + 1);
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) bj[i] = read(), fa[i] = i;
  for (int i = 1; i < n; ++i) {
    int x, y;
    l[i] = read();
    r[i] = read();
    x = find(l[i]), y = find(r[i]);
    if (bj[x] == bj[y]) fa[x] = y;
  }
  for (int i = 1; i <= n; ++i) fa[i] = find(i);
  for (int i = 1; i < n; ++i)
    if (fa[l[i]] != fa[r[i]]) {
      num++;
      p[num].to = fa[r[i]];
      p[num].next = head[fa[l[i]]];
      head[fa[l[i]]] = num;
      num++;
      p[num].to = fa[l[i]];
      p[num].next = head[fa[r[i]]];
      head[fa[r[i]]] = num;
    }
  dfs(fa[1], 0, 0);
  dfs(s, 0, 0);
  cout << (sum + 1) / 2;
  return 0;
}
