#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10;
long long n, m, cm[MAXN], d = 0, dl = 0;
bool col[MAXN], bo[MAXN];
pair<long long, long long> edge[MAXN];
vector<long long> adj[MAXN];
long long Find(long long u) {
  if (u == cm[u]) return u;
  return cm[u] = Find(cm[u]);
}
void merg(long long u, long long v) { u = Find(u), v = Find(v), cm[u] = v; }
void dfs(long long u, long long h) {
  if (h > d) d = h, dl = u;
  bo[u] = true;
  for (long long i = 0; i < (long long)adj[u].size(); i++)
    if (!bo[adj[u][i]]) dfs(adj[u][i], h + 1);
}
int32_t main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> col[i], cm[i] = i;
  for (long long i = 0; i < n - 1; i++) {
    cin >> edge[i].first >> edge[i].second;
    if (col[edge[i].first] == col[edge[i].second])
      merg(edge[i].first, edge[i].second);
  }
  for (long long i = 0; i < n - 1; i++)
    if (col[edge[i].first] != col[edge[i].second])
      adj[Find(edge[i].first)].push_back(Find(edge[i].second)),
          adj[Find(edge[i].second)].push_back(Find(edge[i].first));
  dfs(Find(1), 0), d = 0, memset(bo, false, sizeof bo), dfs(dl, 0);
  return cout << (d + 1) / 2 << endl, 0;
}
