#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int n, dp[200002], cul[200002], ans;
vector<int> v[200002];
void dfs(int dad, int nod) {
  dp[nod] = 1;
  for (int i = 0; i < v[nod].size(); ++i) {
    int vecin = v[nod][i];
    if (vecin == dad) continue;
    dfs(nod, vecin);
    ans = max(ans, dp[nod] + dp[vecin] - (cul[nod] == cul[vecin]));
    dp[nod] = max(dp[nod], dp[vecin] + (cul[nod] != cul[vecin]));
  }
  ans = max(ans, dp[nod]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> cul[i];
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0, 1);
  cout << ans / 2;
  return 0;
}
