#include <bits/stdc++.h>
using namespace std;
int n;
bool c[200010];
vector<int> e[200010];
int ans, maxd[200010];
void dfs(int x, int p, int d) {
  int max1 = 0, max2 = 0;
  for (auto &i : e[x]) {
    if (i == p) continue;
    dfs(i, x, d + (c[x] != c[i]));
    if (maxd[i] > max1) {
      max1 = maxd[i];
      if (max1 > max2) swap(max1, max2);
    }
  }
  ans = max(ans, max2 - d + 1);
  maxd[x] = max(max2, d);
  ans = max(ans, max1 + max2 - 2 * d + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    c[i] = v;
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  dfs(1, 1, 0);
  cout << ans / 2 << "\n";
  return 0;
}
