#include <bits/stdc++.h>
using namespace std;
int n, ps[200005], dis[200005], ans;
bool color[200005];
vector<int> e[200005], g[200005];
void init(int n) {
  for (int i = (1); i <= (n); ++i) ps[i] = i;
}
int fset(int i) { return (ps[i] == i) ? i : ps[i] = fset(ps[i]); }
bool same(int i, int j) { return fset(i) == fset(j); }
void uni(int i, int j) {
  if (!same(i, j)) ps[fset(i)] = fset(j);
}
void dfs(int u, int p, int t) {
  for (int i = 0; i < (e[u].size()); ++i) {
    int v = e[u][i];
    if (p == v) continue;
    dfs(v, u, t);
    if (!t)
      if (color[u] == color[v]) uni(v, u);
    if (t)
      if (color[u] != color[v]) {
        int x = fset(u), y = fset(v);
        g[x].push_back(y);
        g[y].push_back(x);
      }
  }
}
pair<int, int> bfs(int x) {
  for (int i = (1); i <= (n); ++i) dis[i] = -1;
  dis[x] = 0;
  queue<int> q;
  q.push(x);
  int u, v;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < (g[u].size()); ++i) {
      v = g[u][i];
      if (dis[v] == -1) {
        dis[v] = dis[u] + 1;
        q.push(v);
      }
    }
  }
  int d = dis[1], res = 1;
  for (int i = (2); i <= (n); ++i)
    if (dis[i] > d) d = dis[i], res = i;
  return pair<int, int>(res, d);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = (1); i <= (n); ++i) cin >> color[i];
  init(n);
  int u, v;
  for (int i = 0; i < (n - 1); ++i) {
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(1, 0, 0);
  dfs(1, 0, 1);
  pair<int, int> A = bfs(1);
  pair<int, int> B = bfs(A.first);
  ans = B.second;
  if (ans & 1)
    cout << ans / 2 + 1;
  else
    cout << ans / 2;
  return 0;
}
