#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
struct edge {
  int adj, next;
} e[MAXN << 1];
int n, m, cnt, tot, col[MAXN], fa[MAXN], inp[MAXN];
int root, head[MAXN], diam[MAXN], len[MAXN];
pair<int, int> ori[MAXN];
inline void add_edge(int u, int v) {
  tot++;
  e[tot].adj = v, e[tot].next = head[u];
  head[u] = tot;
}
int get_fa(int u) {
  if (u == fa[u])
    return u;
  else
    return fa[u] = get_fa(fa[u]);
}
inline void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &col[i]);
    fa[i] = i;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (col[u] == col[v]) {
      int fu = get_fa(u), fv = get_fa(v);
      if (fu != fv) fa[fv] = fu;
    } else
      ori[m++] = pair<int, int>(u, v);
  }
  for (int i = 1; i <= n; i++) {
    int u = get_fa(i);
    if (!inp[u]) inp[u] = ++cnt;
  }
  for (int i = 0; i < m; i++) {
    int u = inp[get_fa(ori[i].first)], v = inp[get_fa(ori[i].second)];
    add_edge(u, v), add_edge(v, u);
  }
  root = 1;
}
void DFS(int u, int fa) {
  int len2 = 0;
  for (int i = head[u]; i; i = e[i].next) {
    int &v = e[i].adj;
    if (v == fa) continue;
    DFS(v, u);
    if (len[v] + 1 > len[u])
      len2 = len[u], len[u] = len[v] + 1;
    else if (len[v] + 1 > len2)
      len2 = len[v] + 1;
    diam[u] = max(diam[u], diam[v]);
  }
  diam[u] = max(diam[u], len[u] + len2);
}
int main() {
  init();
  DFS(root, 0);
  printf("%d\n", diam[root] + 1 >> 1);
  return 0;
}
