#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, next;
};
int n, cnt, d;
int color[200100 + 1], head[200100 + 1], vis[200100 + 1];
int dp[200100 + 1][2];
struct edge g[200100 << 1 | 1];
inline void addedge(int u, int v) {
  g[cnt] = (edge){v, head[u]};
  head[u] = cnt++;
}
inline void build(int cur, bool col) {
  int i, v;
  vis[cur] = true;
  for (i = head[cur]; ~i; i = g[i].next) {
    v = g[i].v;
    if (!vis[v]) {
      if (color[v] == col) {
        build(v, col);
        if (dp[v][true] > dp[cur][true]) {
          dp[cur][false] = dp[cur][true];
          dp[cur][true] = dp[v][true];
        } else if (dp[v][true] > dp[cur][false]) {
          dp[cur][false] = dp[v][true];
        };
      } else {
        build(v, !col);
        if (dp[v][true] + 1 > dp[cur][true]) {
          dp[cur][false] = dp[cur][true];
          dp[cur][true] = dp[v][true] + 1;
        } else if (dp[v][true] + 1 > dp[cur][false]) {
          dp[cur][false] = dp[v][true] + 1;
        }
      }
    }
  }
  d = max(d, dp[cur][true] + dp[cur][false]);
}
int main() {
  int i, u, v;
  cin >> n;
  memset(head, -1, sizeof(head));
  for (i = 1; i <= n; i++) scanf("%d", &color[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  build(1, color[1]);
  cout << (d + 1 >> 1) << endl;
  return 0;
}
