#include <bits/stdc++.h>
using namespace std;
struct node {
  long long c, g;
  vector<long long> N;
};
node M[200005];
long long C[2], m = 0;
void f(long long j, long long p) {
  vector<long long> V;
  for (long long i = 0; i < M[j].N.size(); i++) {
    long long j2 = M[j].N[i];
    if (p == j2) continue;
    f(j2, j);
    long long g = M[j2].g;
    if (M[j].c != M[j2].c) g++;
    V.push_back(g);
  }
  long long n = V.size();
  if (n == 0) {
    M[j].g = 1;
  } else if (n == 1) {
    M[j].g = V[0];
    m = max(m, M[j].g);
  } else {
    sort(V.begin(), V.end());
    long long l1 = V[n - 1], l2 = V[n - 2];
    M[j].g = l1;
    m = max(m, l1 + l2 - 1);
  }
}
int main() {
  long long n, c, x, y;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> c;
    M[i].c = c;
  }
  for (long long i = 0; i < n - 1; i++) {
    cin >> x >> y;
    x--;
    y--;
    M[x].N.push_back(y);
    M[y].N.push_back(x);
  }
  f(0, -1);
  cout << m / 2;
}
