#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
int n, f[MAXN], a[MAXN], b[MAXN], col[MAXN];
bool vis[MAXN];
template <int _siz>
struct Edge {
  static const int MAXN = _siz << 1;
  int E, head[_siz], nxt[MAXN], pnt[MAXN];
  inline void clear() {
    E = 0;
    memset(head, -1, sizeof(head));
  }
  inline void addedge(int x, int y) {
    nxt[E] = head[x];
    pnt[E] = y;
    head[x] = E++;
  }
};
Edge<MAXN> F, G;
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
inline void join(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) f[fx] = fy;
}
inline void samecol(int u, int fa) {
  for (register int i = F.head[u]; i != -1; i = F.nxt[i]) {
    int v = F.pnt[i];
    if (v != fa && col[v] == col[u] && (!vis[v])) {
      join(v, u);
      vis[v] = 1;
      samecol(v, u);
    }
  }
}
int mxdep, mxid;
inline void dfs(int u, int fa, int dep) {
  if (dep > mxdep) {
    mxdep = dep;
    mxid = u;
  }
  for (register int i = G.head[u]; i != -1; i = G.nxt[i]) {
    int v = G.pnt[i];
    if (v != fa) dfs(v, u, dep + 1);
  }
}
inline void work() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%d", &col[i]);
    f[i] = i;
  }
  F.clear();
  for (register int i = 1; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    F.addedge(a[i], b[i]);
    F.addedge(b[i], a[i]);
  }
  for (register int i = 1; i <= n; ++i)
    if (!vis[i]) samecol(i, -1);
  G.clear();
  for (register int i = 1; i <= n; ++i)
    if (f[a[i]] != f[b[i]]) {
      G.addedge(f[a[i]], f[b[i]]);
      G.addedge(f[b[i]], f[a[i]]);
    }
  dfs(1, -1, 0);
  dfs(mxid, -1, 0);
  printf("%d\n", (mxdep + 1) >> 1);
}
int main() {
  work();
  return 0;
}
