#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, m, color[N];
vector<int> edge[N];
vector<int> ed[N];
bool visit[N];
int dfs(int u) {
  int x = ++m;
  visit[u] = true;
  vector<int> que;
  que.push_back(u);
  for (int i = 0; i < (int)que.size(); ++i) {
    for (int v : edge[que[i]]) {
      if (visit[v]) continue;
      visit[v] = true;
      if (color[v] == color[u]) {
        que.push_back(v);
      } else {
        int y = dfs(v);
        ed[x].push_back(y);
        ed[y].push_back(x);
      }
    }
  }
  return x;
}
int target, dist;
void gao(int u, int parent, int d) {
  if (d > dist) {
    dist = d;
    target = u;
  }
  for (int v : ed[u]) {
    if (v == parent) continue;
    gao(v, u, d + 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &color[i]);
  }
  int u, v;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1);
  gao(1, 0, 0);
  dist = 0;
  gao(target, 0, 0);
  printf("%d\n", (dist + 1) / 2);
  return 0;
}
