#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n;
int sign[N];
int head[N], tot;
struct edge {
  int to, next, s;
} e[N << 1];
void add(int u, int v) {
  int s = (int)(sign[u] != sign[v]);
  e[++tot] = (edge){v, head[u], s};
  head[u] = tot;
}
bool vis[N];
int maxp, maxu;
void dfs(int u, int p) {
  if (maxp < p) {
    maxp = p;
    maxu = u;
  }
  vis[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (!vis[v]) {
      dfs(v, p + e[i].s);
      vis[v] = 0;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sign[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  maxu = 1, maxp = -1;
  dfs(1, 0);
  memset(vis, 0, sizeof(vis));
  maxp = -1;
  dfs(maxu, 0);
  if (maxp == 0)
    printf("0\n");
  else
    printf("%d", (maxp + 1) / 2);
  return 0;
}
