#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int d[N], color[N], f[N], ans, n, m;
vector<int> a[N];
void dfs(int u, int d, int par) {
  if (d >= ans) ans = d, m = u;
  for (int i = (0), _b = (a[u].size() - 1); i <= _b; ++i) {
    int v = a[u][i];
    if (v != par) dfs(v, d + (color[u] != color[v]), u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; ++i) scanf("%d", &color[i]);
  for (int i = (1), _b = (n - 1); i <= _b; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
  dfs(1, 0, 0);
  dfs(m, 0, 0);
  printf("%d\n", (ans + 1) / 2);
}
