#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, val[MAXN], fa[MAXN], u[MAXN], v[MAXN], rt, dep[MAXN], maxx, rt2;
vector<int> G[MAXN];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void dfs(int x, int f) {
  if (dep[x] > maxx) {
    maxx = dep[x];
    rt2 = x;
  }
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i];
    if (v == f) continue;
    dep[v] = dep[x] + 1;
    dfs(v, x);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]), fa[i] = i;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u[i], &v[i]);
    if (val[u[i]] == val[v[i]]) {
      int x = find(u[i]), y = find(v[i]);
      if (x != y) fa[x] = y;
    }
  }
  for (int i = 1; i <= n; i++)
    if (fa[i] == i) {
      rt = i;
      break;
    }
  for (int i = 1; i < n; i++)
    if (val[u[i]] != val[v[i]]) {
      int x = find(u[i]), y = find(v[i]);
      G[x].push_back(y);
      G[y].push_back(x);
    }
  dfs(rt, 0);
  dep[rt2] = 0;
  dfs(rt2, 0);
  printf("%d", (maxx + 1) / 2);
  return 0;
}
