#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200033;
int n;
bool col[MAXN];
struct edge {
  int t, nx;
} E[MAXN << 1], E_[MAXN << 1];
int first[MAXN], edges_nums = 0;
inline void add(int f, int t) {
  E[++edges_nums].t = t;
  E[edges_nums].nx = first[f];
  first[f] = edges_nums;
}
int first_[MAXN], edges_nums_ = 0;
inline void add_(int f, int t) {
  E_[++edges_nums_].t = t;
  E_[edges_nums_].nx = first_[f];
  first_[f] = edges_nums_;
}
bool check[MAXN];
int nums_of_gp, bel[MAXN];
void uni(int e, int c, int fa) {
  int t;
  for (int i = first[e]; i; i = E[i].nx) {
    t = E[i].t;
    if (col[t] == c && !check[t] && t != fa) {
      check[t] = 1;
      bel[t] = nums_of_gp;
      uni(t, c, e);
    }
  }
}
int fa[MAXN];
int find(int e) { return fa[e] == e ? e : fa[e] = find(fa[e]); }
void union_(int a, int b) {
  int e1 = find(a);
  int e2 = find(b);
  if (e1 != e2) fa[e1] = e2;
}
int MX, S;
void dfs(int sum, int e, int fa) {
  if (sum > MX) {
    MX = sum;
    S = e;
  }
  int t;
  for (int i = first_[e]; i; i = E_[i].nx) {
    t = E_[i].t;
    if (t != fa) dfs(sum + 1, t, e);
  }
}
int main() {
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    add(a, b);
    add(b, a);
  }
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    if (!check[i]) {
      nums_of_gp++;
      bel[i] = nums_of_gp;
      uni(i, col[i], 0);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = first[i]; j; j = E[j].nx) {
      int f = bel[i];
      int t = bel[E[j].t];
      if (find(f) != find(t)) {
        union_(f, t);
        add_(f, t);
        add_(t, f);
      }
    }
  }
  dfs(0, 1, 0);
  MX = 0;
  dfs(0, S, 0);
  if (nums_of_gp > 1)
    printf("%d", (MX + 1) >> 1);
  else
    printf("0");
  return 0;
}
