#include <bits/stdc++.h>
using namespace std;
inline long long bip(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % mod;
    }
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
const int maxn = 1e9;
const int mod = 998244353;
const int N = 2e5 + 10;
int n, c[N], num[N], k = 1, dist, x = 1;
vector<int> g[N], new_g[N];
void dfs(int v) {
  num[v] = k;
  for (int to : g[v]) {
    if (!num[to] && c[to] == c[v]) {
      dfs(to);
    }
  }
}
void dfs2(int v, int p) {
  for (int to : g[v]) {
    if (to == p) continue;
    if (num[v] != num[to]) {
      new_g[num[v]].push_back(num[to]);
      new_g[num[to]].push_back(num[v]);
    }
    dfs2(to, v);
  }
}
void dfs3(int v, int p, int d) {
  if (d > dist) {
    x = v;
    dist = d;
  }
  for (auto to : new_g[v]) {
    if (to == p) continue;
    dfs3(to, v, d + 1);
  }
}
void dfs4(int v, int p, int d) {
  dist = max(dist, d);
  for (auto to : new_g[v]) {
    if (to == p) continue;
    dfs4(to, v, d + 1);
  }
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y), g[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!num[i]) {
      dfs(i);
      k++;
    }
  }
  dfs2(1, -1);
  dfs3(1, -1, 0);
  dist = 0;
  dfs4(x, -1, 0);
  cout << (dist + 1) / 2;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
    cout << '\n';
  }
}
