#include <bits/stdc++.h>
using namespace std;
vector<long long> vec[200020];
long long c[2000200], u, v, deep = 0;
void dfs(long long cur, long long pre, long long d) {
  if (pre != -1)
    if (c[pre] != c[cur]) d++;
  if (deep < d) {
    deep = d;
    u = cur;
  }
  long long Size = vec[cur].size();
  for (long long i = 0; i < Size; i++)
    if (vec[cur][i] != pre) dfs(vec[cur][i], cur, d);
  return;
}
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", c + i);
  for (long long i = 2; i <= n; i++) {
    scanf("%lld %lld", &u, &v);
    vec[u].push_back(v);
    vec[v].push_back(u);
  }
  dfs(1, -1, 0);
  dfs(u, -1, 1);
  printf("%lld\n", deep >> 1);
  return 0;
}
