#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<vector<int>> adj1;
vector<int> c;
void dfs(int v = 0, int p = -1, int k = 0) {
  for (auto nbr : adj[v]) {
    if (nbr != p) {
      if (c[v] != c[nbr]) {
        adj1[k].push_back(nbr);
        adj1[nbr].push_back(k);
        dfs(nbr, v, nbr);
      } else
        dfs(nbr, v, k);
    }
  }
}
int far = 0;
int d = 0;
void dfs1(int v = 0, int p = -1, int l = 0) {
  if (l > d) {
    far = v;
    d = l;
  }
  for (auto nbr : adj1[v]) {
    if (nbr != p) dfs1(nbr, v, l + 1);
  }
}
void solve(int tc) {
  int n;
  cin >> n;
  c = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> c[i];
  adj = vector<vector<int>>(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  adj1 = vector<vector<int>>(n);
  dfs();
  dfs1();
  d = 0;
  dfs1(far);
  cout << (d + 1) / 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
    cout << "\n";
  }
  return 0;
}
