#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int MAXN = 2E5 + 100;
struct node {
  int to, next;
} e[2 * MAXN];
int tol = 0;
int head[MAXN];
void add(int u, int v) {
  e[++tol].to = v, e[tol].next = head[u], head[u] = tol;
  e[++tol].to = u, e[tol].next = head[v], head[v] = tol;
}
int c[MAXN];
pair<int, int> dfs(int u, int fa, int d) {
  pair<int, int> tmp = make_pair(d, u), t;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    if (c[u] == c[v])
      t = dfs(v, u, d);
    else
      t = dfs(v, u, d + 1);
    tmp = max(tmp, t);
  }
  return tmp;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    tol = 0;
    for (int i = 1; i < n + 1; i++) scanf("%d", &c[i]);
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
    }
    pair<int, int> t = dfs(1, -1, 0);
    pair<int, int> tt = dfs(t.second, -1, 0);
    printf("%d\n", (tt.first + 1) / 2);
  }
  return 0;
}
