#include <bits/stdc++.h>
using namespace std;
const int e = 200000 + 10;
int n;
int col[e];
int cnt = 0, head[e];
int fa[e];
struct nod {
  int to, nxt;
} s[e * 2], z[e * 2];
void add(int a, int b) {
  cnt++;
  s[cnt].nxt = head[a];
  s[cnt].to = b;
  head[a] = cnt;
}
int bel[e], tot = 1;
int father(int x) {
  if (fa[x] == x) return x;
  fa[x] = father(fa[x]);
  return fa[x];
}
int hed[e], cntt = 0;
int co[e];
void add2(int a, int b) {
  cntt++;
  z[cntt].nxt = hed[a];
  z[cntt].to = b;
  hed[a] = cntt;
}
void dfs(int from, int to) {
  for (int i = head[to]; i; i = s[i].nxt) {
    int d = s[i].to;
    if (d == from) continue;
    if (col[d] == col[to]) {
      bel[d] = bel[to];
    } else {
      ++tot;
      bel[d] = tot;
    }
    dfs(to, d);
  }
}
void build(int from, int to) {
  co[bel[to]] = col[to];
  for (int i = head[to]; i; i = s[i].nxt) {
    int d = s[i].to;
    if (d == from) continue;
    if (col[d] != col[to]) {
      add2(bel[to], bel[d]);
      add2(bel[d], bel[to]);
    }
    build(to, d);
  }
}
int f[e], dd[e];
int ans = 0;
void dp(int from, int to, int de) {
  f[to] = 1;
  int maxx = 0;
  for (int i = hed[to]; i; i = z[i].nxt) {
    int d = z[i].to;
    if (d == from) continue;
    dp(to, d, de + 1);
    if (maxx + f[d] + 1 > ans) ans = maxx + f[d] + 1;
    maxx = max(maxx, f[d]);
  }
  f[to] += maxx;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
    fa[i] = i;
  }
  int a, b;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  bel[1] = 1;
  for (int i = head[1]; i; i = s[i].nxt) {
    int g = s[i].to;
    if (col[g] == col[1])
      bel[g] = 1;
    else {
      tot++;
      bel[g] = tot;
    }
    dfs(1, g);
  }
  build(0, 1);
  dp(0, 1, 1);
  cout << ans / 2;
  return 0;
}
