#include <bits/stdc++.h>
using namespace std;
void dfs(const int cur, const int prev, const int comp, int& cur_comp,
         const vector<int>& color, const vector<vector<int>>& vec,
         vector<vector<int>>& comp_vec) {
  for (const auto next : vec[cur]) {
    if (next == prev) continue;
    if (color[cur] == color[next]) {
      dfs(next, cur, comp, cur_comp, color, vec, comp_vec);
      continue;
    }
    comp_vec[comp].push_back(cur_comp);
    comp_vec[cur_comp].push_back(comp);
    ++cur_comp;
    dfs(next, cur, cur_comp - 1, cur_comp, color, vec, comp_vec);
  }
}
pair<int, int> far_point(const int cur, const int prev,
                         const vector<vector<int>>& vec, const int dist) {
  pair<int, int> rez(dist, cur);
  for (const auto next : vec[cur]) {
    if (next == prev) continue;
    rez = max(rez, far_point(next, cur, vec, dist + 1));
  }
  return rez;
}
void mk_path(const int cur, const int prev, const vector<vector<int>>& vec,
             const int target, vector<int>& cur_path, vector<int>& rez) {
  cur_path.push_back(cur);
  if (cur == target) {
    rez = cur_path;
    cur_path.pop_back();
    return;
  }
  for (const auto next : vec[cur]) {
    if (next == prev) continue;
    mk_path(next, cur, vec, target, cur_path, rez);
  }
  cur_path.pop_back();
}
int main() {
  int n;
  cin >> n;
  vector<int> color(n), weight(n), color_weight(n);
  vector<vector<int>> vec(n), comp_vec(n);
  for (auto& x : color) cin >> x;
  for (int i = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    --x, --y;
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  int cur_comp = 1;
  dfs(0, -1, 0, cur_comp, color, vec, comp_vec);
  auto fp1 = far_point(0, -1, comp_vec, 0),
       fp2 = far_point(fp1.second, -1, comp_vec, 0);
  const int diam1 = fp1.second, diam2 = fp2.second;
  vector<int> cur_path, full_diam;
  mk_path(diam1, -1, comp_vec, diam2, cur_path, full_diam);
  double mid = (full_diam.size() - 1.0) / 2.0;
  const int candidate1 = full_diam[(int)floor(mid)],
            candidate2 = full_diam[(int)ceil(mid)];
  const int dist1 = far_point(candidate1, -1, comp_vec, 0).first,
            dist2 = far_point(candidate2, -1, comp_vec, 0).first;
  cout << min(dist1, dist2) << endl;
  return 0;
}
