#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> edge[200010];
vector<long long> tr1[200010], tr2[200010];
long long n;
long long c[200010];
long long flag[200010], tot = 0;
long long dia[200010];
long long dia1, dia2;
void Predfs(long long u, long long fa, long long cc) {
  flag[u] = cc;
  for (long long i = 0; i < tr1[u].size(); i++) {
    long long v = tr1[u][i];
    if (v == fa || flag[v] != 0) {
      continue;
    }
    if (c[u] != c[v]) {
      continue;
    }
    Predfs(v, u, cc);
  }
}
void Diadfs(long long u, long long fa) {
  for (long long i = 0; i < tr2[u].size(); i++) {
    long long v = tr2[u][i];
    if (v == fa) {
      continue;
    }
    dia[v] = dia[u] + 1;
    Diadfs(v, u);
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    edge[i] = make_pair(x, y);
    tr1[x].push_back(y);
    tr1[y].push_back(x);
  }
  for (long long i = 1; i <= n; i++) {
    if (flag[i] != 0) {
      continue;
    }
    tot++;
    Predfs(i, 0, tot);
  }
  for (long long i = 1; i < n; i++) {
    long long u = edge[i].first;
    long long v = edge[i].second;
    if (flag[u] != flag[v]) {
      tr2[flag[u]].push_back(flag[v]);
      tr2[flag[v]].push_back(flag[u]);
    }
  }
  Diadfs(1, 0);
  long long mx = -1;
  dia1 = -1;
  for (long long i = 1; i <= n; i++) {
    if (dia[i] > mx) {
      mx = dia[i];
      dia1 = i;
    }
    dia[i] = 0;
  }
  Diadfs(dia1, 0);
  mx = -1;
  dia2 = -1;
  for (long long i = 1; i <= n; i++) {
    if (dia[i] > mx) {
      mx = dia[i];
      dia2 = i;
    }
  }
  cout << ceil(1.0 * mx / 2.0) << endl;
  return 0;
}
