#include <bits/stdc++.h>
using namespace std;
struct dsu {
  vector<int> P, rank;
  dsu(int n) : P(n), rank(n) {
    for (int i = 0; i < n; i++) {
      P[i] = i;
      rank[i] = 0;
    }
  }
  int fnd(int i) {
    if (i != P[i]) P[i] = fnd(P[i]);
    return P[i];
  }
  void join(int x, int y) {
    int PX = fnd(x);
    int PY = fnd(y);
    if (rank[PX] > rank[PY])
      P[PY] = PX;
    else
      P[PX] = PY;
    if (rank[PX] == rank[PY]) rank[PY] = rank[PX] + 1;
  }
};
int col[200010];
bool vis[200010];
vector<int> adj[200010];
set<int> ff[200010];
int dis[200010], dis2[100010];
int mx = 0, ind;
void dfs(int i, int par, int dep) {
  dis[i] = dep;
  if (dep >= mx) ind = i, mx = dep;
  for (auto j : ff[i]) {
    if (j == par or j == i) continue;
    dfs(j, i, dep + 1);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &col[i]);
  dsu d(n + 2);
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d", &x);
    scanf("%d", &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
    if (col[x] == col[y]) d.join(x, y);
  }
  for (int i = 1; i <= n; ++i) {
    int tp = d.fnd(i);
    for (auto j : adj[i]) {
      ff[tp].insert(d.fnd(j));
    }
  }
  int far;
  dfs(d.fnd(1), 0, 0);
  mx = 0;
  dfs(ind, 0, 0);
  cout << (mx + 1) / 2 << endl;
}
