#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> V[N];
int col[N];
pair<int, int> temp;
void dfs(int root, int son, int deep) {
  temp = max(temp, make_pair(deep, son));
  for (int i = 0; i < V[son].size(); i++) {
    int u = V[son][i];
    if (u == root) continue;
    if (col[u] == col[son])
      dfs(son, u, deep);
    else
      dfs(son, u, deep + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, i, j, u, v;
  pair<int, int> t;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> col[i];
  for (i = 1; i < n; i++) {
    cin >> u >> v;
    V[u].push_back(v);
    V[v].push_back(u);
  }
  temp = make_pair(0, 0);
  dfs(-1, 1, 0);
  t = temp;
  temp = make_pair(0, 0);
  dfs(-1, t.second, 0);
  int ans = (temp.first + 1) >> 1;
  cout << ans << endl;
  return 0;
}
