#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double E = 1e-8;
const double PI = acos(-1);
const int NMAX = 222222;
int n, res, cnt;
int c[NMAX], lab[NMAX], Fre[NMAX], d[NMAX];
vector<int> head[NMAX], ke[NMAX];
void DFS(int u) {
  Fre[u] = false;
  lab[u] = cnt;
  for (auto v : head[u]) {
    if (Fre[v] && c[u] == c[v]) DFS(v);
  }
}
void visit(int u, int pa) {
  d[u] = 0;
  for (auto v : ke[u]) {
    if (v == pa) continue;
    visit(v, u);
    res = max(res, d[u] + d[v] + 1);
    d[u] = max(d[u], d[v] + 1);
  }
}
int main() {
  cin >> n;
  for (int i = (1); i <= (n); i++) scanf("%d", &c[i]);
  for (int i = (1); i <= (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    head[u].push_back(v);
    head[v].push_back(u);
  }
  for (int i = (1); i <= (n); i++) Fre[i] = true;
  for (int i = (1); i <= (n); i++)
    if (Fre[i]) {
      cnt++;
      DFS(i);
    }
  for (int u = (1); u <= (n); u++)
    for (auto v : head[u])
      if (lab[u] != lab[v]) {
        ke[lab[u]].push_back(lab[v]);
      }
  res = 0;
  visit(1, 0);
  res++;
  cout << res / 2 << endl;
}
