#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
vector<int> g[maxn], com[maxn], col(maxn), comp(maxn), dist(maxn);
int n, dia;
void dfs(int u, int par, int c) {
  comp[u] = c;
  for (auto v : g[u])
    if (par - v) {
      if (col[u] == col[v]) dfs(v, u, c);
    }
}
void DDfs(int u, int par) {
  int mx1 = 0, mx2 = 0;
  for (auto v : com[u])
    if (v - par) {
      DDfs(v, u);
      int curr = dist[v] + 1;
      mx2 = max(mx2, curr);
      if (mx2 > mx1) swap(mx2, mx1);
    }
  dist[u] = mx1;
  dia = max(dia, mx1 + mx2);
}
int main() {
  cin >> n;
  int u, v;
  for (int i = 0; i < n; i++) cin >> col[i], comp[i] = -1;
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int idx = 0;
  for (int i = 0; i < n; i++)
    if (comp[i] == -1) {
      dfs(i, -1, idx++);
    }
  for (int u = 0; u < n; u++) {
    for (int v : g[u]) {
      if (comp[u] != comp[v]) {
        com[comp[u]].push_back(comp[v]);
      }
    }
  }
  DDfs(0, -1);
  cout << (dia + 1) / 2 << endl;
  return 0;
}
