#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int c[maxn];
int comp[maxn];
set<int> graph2[maxn];
vector<int> graph[maxn];
void dfs(int u, int p, int com) {
  if (c[u] != c[p]) return;
  comp[u] = com;
  for (auto &v : graph[u]) {
    if (v == p) continue;
    dfs(v, u, com);
  }
}
int ma, mv;
void dfs1(int u, int p, int dis) {
  if (dis > ma) {
    ma = dis;
    mv = u;
  }
  for (auto &v : graph2[u]) {
    if (v == p || v == u) continue;
    dfs1(v, u, dis + 1);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  int com = 1;
  for (int i = 1; i <= n; i++) {
    if (comp[i] == 0) dfs(i, i, com++);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < graph[i].size(); j++) {
      graph2[comp[i]].insert(comp[graph[i][j]]);
    }
  }
  dfs1(1, 1, 0);
  ma = 0;
  dfs1(mv, mv, 0);
  printf("%d\n", (ma + 1) / 2);
  return 0;
}
