#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
int c[N];
vector<int> edge[N];
bool vis[N];
int lst;
int bfs(int s) {
  memset(vis, 0, sizeof vis);
  queue<int> q[2];
  int cur = c[s];
  q[cur].push(s);
  vis[s] = 1;
  int ans = -1;
  while (q[cur].size()) {
    while (q[cur].size()) {
      int u = q[cur].front();
      lst = u;
      q[cur].pop();
      for (int v : edge[u]) {
        if (vis[v]) continue;
        vis[v] = 1;
        q[c[v]].push(v);
      }
    }
    ans++;
    cur ^= 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", c + i);
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    --u, --v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  bfs(0);
  printf("%d\n", bfs(lst) + 1 >> 1);
  return 0;
}
