#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int a[N], n, u, v, dep, root;
struct Edge {
  int head[N], next[N << 1], v[N << 1], e;
  void clear() { memset(head, -1, sizeof(head)); }
  void add(int u, int v) {
    this->v[e] = v;
    next[e] = head[u];
    head[u] = e++;
  }
} G;
void dfs(int fa, int rt, int d) {
  if (d > dep) {
    dep = d;
    root = rt;
  }
  for (int e = G.head[rt]; ~e; e = G.next[e]) {
    if (G.v[e] != fa) dfs(rt, G.v[e], d + (a[rt] != a[G.v[e]]));
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  G.clear();
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    G.add(u, v);
    G.add(v, u);
  }
  dep = 0;
  dfs(-1, 1, 1);
  dep = 0;
  dfs(-1, root, 1);
  cout << dep / 2 << endl;
  return 0;
}
