#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f(1);
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
template <typename T>
void write(T x, int f = 1) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar('0' + x % 10);
  if (f) puts("");
}
const int maxn = 200005;
int n, C[maxn], hd[maxn], cnt, az[maxn];
int U[maxn], V[maxn], fa[maxn];
int num, S, T, Adis;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
struct edge {
  int ed, nxt;
} e[2 * maxn];
void star(int u, int v) {
  e[++cnt].ed = v;
  e[cnt].nxt = hd[u];
  hd[u] = cnt;
}
void dfs(int, int, int);
int main() {
  read(n);
  for (int i(1); i <= n; ++i) fa[i] = i, read(C[i]);
  for (int i(1); i < n; ++i) {
    read(U[i]), read(V[i]);
    if (C[U[i]] == C[V[i]]) {
      int uf = find(U[i]);
      int vf = find(V[i]);
      fa[vf] = uf;
    }
  }
  for (int i(1); i <= n; ++i)
    if (fa[i] == i) az[i] = ++num;
  for (int i(1); i < n; ++i) {
    if (find(U[i]) == find(V[i])) continue;
    star(az[find(U[i])], az[find(V[i])]);
    star(az[find(V[i])], az[find(U[i])]);
  }
  T = 1;
  dfs(1, 0, 0);
  Adis = 0;
  S = T;
  dfs(S, 0, 0);
  write((Adis + 1) / 2);
  return 0;
}
void dfs(int x, int tdis, int f) {
  if (tdis > Adis) T = x, Adis = tdis;
  for (int i = hd[x]; i; i = e[i].nxt) {
    int y = e[i].ed;
    if (y == f) continue;
    dfs(y, tdis + 1, x);
  }
}
