#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100100;
int n, uf[MAXN], c[MAXN];
vector<pair<int, int>> e;
vector<int> g[MAXN];
inline int find(int x) {
  if (!uf[x]) return x;
  return uf[x] = find(uf[x]);
}
inline void join(int x, int y) { uf[find(y)] = find(x); }
pair<int, int> dfs(int v, int p = -1) {
  pair<int, int> ans(1, v), aux;
  for (const int& u : g[v])
    if (u != p) aux = dfs(u, v), aux.first++, ans = max(ans, aux);
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  for (int i = 1, u, v; i < n; ++i)
    scanf("%d %d", &u, &v), (c[u] == c[v] ? join(u, v) : void()),
        e.push_back(make_pair(u, v));
  for (const auto& [u, v] : e)
    if (find(u) != find(v))
      g[find(u)].push_back(find(v)), g[find(v)].push_back(find(u));
  int d1, d2, d;
  d1 = dfs(find(1)).second, tie(d, d2) = dfs(d1);
  printf("%d\n", d / 2);
}
