#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<pair<int, int> > g[maxn];
set<pair<int, int> > s;
int c[maxn], dis[maxn];
void dijekstra(int u) {
  dis[u] = 0;
  s.insert(make_pair(u, dis[u]));
  while (s.size()) {
    pair<int, int> a = *s.begin();
    s.erase(a);
    for (int i = 0; i < g[a.first].size(); i++) {
      if (a.second + g[a.first][i].second < dis[g[a.first][i].first]) {
        s.erase(make_pair(g[a.first][i].first, dis[g[a.first][i].first]));
        dis[g[a.first][i].first] = a.second + g[a.first][i].second;
        s.insert(make_pair(g[a.first][i].first, dis[g[a.first][i].first]));
      }
    }
  }
  s.clear();
}
int main() {
  ios_base::sync_with_stdio(false);
  memset(dis, 63, sizeof(dis));
  int n, x, y;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    if (c[x] == c[y]) {
      g[x].push_back(make_pair(y, 0));
      g[y].push_back(make_pair(x, 0));
    } else {
      g[x].push_back(make_pair(y, 1));
      g[y].push_back(make_pair(x, 1));
    }
  }
  dijekstra(1);
  int mx = -1, j;
  for (int i = 1; i <= n; i++)
    if (dis[i] > mx) mx = dis[i], j = i;
  memset(dis, 63, sizeof(dis));
  dijekstra(j);
  mx = -1;
  for (int i = 1; i <= n; i++)
    if (dis[i] > mx) mx = dis[i], j = i;
  cout << (dis[j] + 1) / 2;
  return 0;
}
