#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 69;
int n, X, x, y, ind, ans;
int A[N];
vector<int> gr[N], gr1[N];
int fix[N], fix1[N], dp[N][2];
queue<int> q;
void dfs(int x, int c) {
  fix[x] = 1;
  for (int i = 0; i < gr[x].size(); i++) {
    int to = gr[x][i];
    if (fix[to]) continue;
    if (A[to] != c) {
      q.push(to);
      gr1[X].push_back(to);
      gr1[to].push_back(X);
    } else {
      dfs(to, c);
    }
  }
}
void dfs1(int x, int p, int depth) {
  if (ans < depth) {
    ans = depth;
    ind = x;
  }
  for (int i = 0; i < gr1[x].size(); i++) {
    int to = gr1[x][i];
    if (to == p) continue;
    dfs1(to, x, depth + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  q.push(1);
  while (q.size()) {
    X = q.front();
    q.pop();
    dfs(X, A[X]);
  }
  dfs1(1, 0, 1);
  dfs1(ind, 0, 1);
  cout << ans / 2 << endl;
}
