#include <bits/stdc++.h>
using namespace std;
struct bag {
  int x, y;
};
const int maxn = 2e5 + 1;
vector<int> g[maxn], h[maxn];
bool visited[maxn];
int n, c[maxn], p[maxn];
bag dfs(int v, int d) {
  visited[v] = 1;
  bag res;
  res.x = v;
  res.y = d;
  for (int u : h[v]) {
    if (!visited[u]) {
      bag t = dfs(u, d + 1);
      if (t.y > res.y) res = t;
    }
  }
  return res;
}
void part(int v, int x) {
  visited[v] = 1;
  p[v] = x;
  for (int u : g[v])
    if (!visited[u])
      if (c[u] == c[v]) part(u, x);
}
void collapse(int v) {
  visited[v] = 1;
  for (int u : g[v])
    if (p[v] == p[u]) {
      if (!visited[u]) collapse(u);
    } else {
      h[p[v]].push_back(p[u]);
    }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1, v, u; i < n; i++) {
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  int t = 1;
  for (int i = 1; i <= n; i++)
    if (!visited[i]) part(i, t), t++;
  fill(visited, visited + maxn, 0);
  for (int i = 1; i <= n; i++)
    if (!visited[i]) collapse(i);
  fill(visited, visited + maxn, 0);
  int v = dfs(1, 0).x;
  fill(visited, visited + maxn, 0);
  int d = dfs(v, 0).y;
  cout << (d + 1) / 2 << endl;
}
