#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, color[N];
vector<int> adj[N], new_adj[N];
int vis[N], topo[N];
void dfs(int u, int id) {
  vis[u] = 1;
  topo[u] = id;
  for (int v : adj[u]) {
    if (vis[v] || color[v] != color[u]) continue;
    dfs(v, id);
  }
}
int d[N], Dist, farr;
void dfs2(int u, int dad = 0) {
  d[u] = d[dad] + 1;
  if (d[u] > Dist) Dist = d[u], farr = u;
  for (int v : new_adj[u]) {
    if (v == dad) continue;
    dfs2(v, u);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> color[i];
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  int id = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) ++id, dfs(i, id);
  for (int i = 1; i <= n; ++i)
    for (int v : adj[i])
      if (color[i] != color[v]) new_adj[topo[i]].push_back(topo[v]);
  memset(d, -1, sizeof d);
  Dist = 0;
  dfs2(1);
  memset(d, -1, sizeof d);
  Dist = 0;
  dfs2(farr);
  cout << (Dist + 1) / 2;
}
