#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
vector<int> e[maxn];
bool color[maxn];
int comp[maxn];
int maxd[maxn], secd[maxn];
int compOf(int v) {
  if (comp[v] != v) comp[v] = compOf(comp[v]);
  return comp[v];
}
void merge(int u, int v) {
  u = compOf(u);
  v = compOf(v);
  comp[v] = u;
}
vector<int> f[maxn];
bool seen[maxn];
int ans = 0;
void dfs(int v) {
  seen[v] = true;
  for (int u : f[v]) {
    if (seen[u]) continue;
    dfs(u);
    if (maxd[u] >= maxd[v]) {
      secd[v] = maxd[v];
      maxd[v] = maxd[u];
    } else if (maxd[u] > secd[v]) {
      secd[v] = maxd[u];
    }
  }
  maxd[v]++;
  secd[v]++;
  ans = max(ans, maxd[v] + secd[v] - 1);
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> color[i];
    comp[i] = i;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
    if (color[u] == color[v]) {
      merge(u, v);
    }
  }
  for (int i = 1; i <= n; i++) {
    int v = compOf(i);
    for (int u : e[i]) {
      int w = compOf(u);
      if (w != v) {
        f[v].push_back(w);
      }
    }
  }
  dfs(compOf(1));
  cout << ans / 2 << '\n';
  return 0;
}
