#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int N = 200005;
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
int n, head[N], c[N], f[N], s[N], t[N], cnt, dp[N], ans;
bool vis[N];
struct node {
  int v, nxt;
} e[N << 1];
inline void add(int u, int v) { e[++cnt] = (node){v, head[u]}, head[u] = cnt; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void dpp(int u, int fa) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    dpp(v, u);
    ans = max(ans, dp[u] + dp[v] + 1);
    dp[u] = max(dp[u], dp[v] + 1);
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(c[i]), f[i] = i;
  for (int i = 1; i < n; ++i) {
    read(s[i]), read(t[i]);
    if (c[s[i]] == c[t[i]]) {
      int f1 = find(s[i]), f2 = find(t[i]);
      f[f2] = f1;
    }
  }
  int f1 = 1, f2 = 1;
  for (int i = 1; i < n; ++i) {
    f1 = find(s[i]), f2 = find(t[i]);
    if (f1 != f2) add(f1, f2), add(f2, f1);
  }
  dpp(f1, 0);
  printf("%d\n", (ans + 1) >> 1);
  return 0;
}
