#include <bits/stdc++.h>
using namespace std;
int n;
int c[200010], d[200010];
vector<int> G[200010];
void Dfs(int u, int f) {
  for (auto &v : G[u])
    if (v != f) {
      d[v] = c[u] == c[v] ? d[u] : d[u] + 1;
      Dfs(v, u);
    }
}
int main() {
  ios::sync_with_stdio(false);
  int i, u, v, ans;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> c[i];
  for (i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  d[1] = 0;
  Dfs(1, -1);
  ans = 0;
  for (i = 1; i <= n; ++i)
    if (d[i] > ans) {
      ans = d[i];
      u = i;
    }
  d[u] = 0;
  Dfs(u, -1);
  ans = 0;
  for (i = 1; i <= n; ++i)
    if (d[i] > ans) {
      ans = d[i];
      v = i;
    }
  cout << (ans + 1) / 2 << endl;
  return 0;
}
