#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<vector<int> > g, g1;
int color[N], p[N], visited[N], dp[N];
int ans = 0, cnt = 0;
void unite(int v, int col, int id) {
  if (visited[v]) return;
  if (color[v] != col) return;
  visited[v] = 1;
  p[v] = id;
  for (int i = 0; i < (((int)(g[v]).size())); ++i) {
    int to = g[v][i];
    unite(to, col, id);
  }
}
void dfs(int v, int parent = -1) {
  int mx1 = 0, mx2 = 0;
  for (int i = 0; i < (((int)(g1[v]).size())); ++i) {
    int to = g1[v][i];
    if (to == parent) continue;
    dfs(to, v);
    int val = dp[to] + 1;
    mx2 = max(mx2, val);
    if (mx1 < mx2) swap(mx1, mx2);
  }
  dp[v] = mx1;
  ans = max(ans, mx1 + mx2);
}
int main() {
  int n, a, b;
  cin >> n;
  for (int i = 0; i < (n); ++i) cin >> color[i];
  for (int i = 0; i < (n); ++i) p[i] = i;
  g.resize(n);
  for (int i = 0; i < (n - 1); ++i) {
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < (n); ++i)
    if (!visited[i]) unite(i, color[i], cnt++);
  g1.resize(cnt);
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (((int)(g[i]).size())); ++j) {
      int to = g[i][j];
      if (p[i] != p[to]) g1[p[i]].push_back(p[to]);
    }
  dfs(0);
  cout << (ans + 1) / 2 << endl;
  return 0;
}
