#include <bits/stdc++.h>
using namespace std;
const int N = 300100;
inline int read() {
  int x = 0, c = getchar(), f = 0;
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int L, ne[N << 1], to[N << 1], h[N], f[N][2], a[N];
void add(int x, int y) {
  ne[++L] = h[x];
  h[x] = L;
  to[L] = y;
  ne[++L] = h[y];
  h[y] = L;
  to[L] = x;
}
pair<int, int> dfs(int x, int fa, int g) {
  pair<int, int> s = make_pair(g, x);
  for (int k = h[x]; k; k = ne[k])
    if (to[k] != fa) s = max(s, dfs(to[k], x, g + (a[x] ^ a[to[k]])));
  return s;
}
int main() {
  int i, n = read();
  for (i = 1; i <= n; i++) a[i] = read();
  for (i = 1; i < n; i++) add(read(), read());
  printf("%d\n", (dfs(dfs(1, 0, 0).second, 0, 0).first + 1) / 2);
  return 0;
}
