#include <bits/stdc++.h>
using namespace std;
int color[200005];
vector<int> d[200005];
vector<int> g[200005];
set<int> g2[200005];
int p[200005];
bool v[200005];
int black, white;
int n;
void dfs(int u, int root) {
  v[u] = true;
  p[u] = root;
  for (auto x : g[u]) {
    if (!v[x]) {
      dfs(x, root);
    }
  }
}
int height, root;
void dfs2(int u, int lvl) {
  if (lvl > height) {
    height = lvl;
    root = u;
  }
  v[u] = 1;
  for (auto x : g2[u]) {
    if (!v[x]) {
      dfs2(x, lvl + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, j, k, x, y;
  cin >> n;
  for (i = 0; i < n; i++) cin >> color[i];
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    x--;
    y--;
    if (color[x] == color[y]) {
      g[x].push_back(y);
      g[y].push_back(x);
    } else {
      d[x].push_back(y);
      d[y].push_back(x);
    }
  }
  memset(v, false, sizeof(v));
  for (i = 0; i < n; i++) {
    if (!v[i]) {
      if (color[i] == 0)
        white++;
      else
        black++;
      dfs(i, i);
    }
  }
  for (i = 0; i < n; i++) {
    for (auto x : d[i]) {
      g2[p[i]].insert(p[x]);
      g2[p[x]].insert(p[i]);
    }
  }
  memset(v, 0, sizeof(v));
  dfs2(p[0], 0);
  height = 0;
  memset(v, 0, sizeof(v));
  dfs2(root, 0);
  cout << ((height + 1) >> 1) << "\n";
  return 0;
}
