#include <bits/stdc++.h>
using namespace std;
const int UNDEF = -1;
const int INF = 1e9;
template <typename T>
inline bool chkmax(T &aa, T bb) {
  return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T &aa, T bb) {
  return aa > bb ? aa = bb, true : false;
}
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
const int mn = 2e5 + 4;
int n;
int vc[mn];
vector<int> g[mn];
bool seen[mn];
int dist[mn];
void dfs(int x) {
  for (auto &y : g[x]) {
    if (dist[y] == -1) {
      dist[y] = dist[x] + 1;
      dfs(y);
    }
  }
}
vector<int> h[mn];
void pre(int x, int r) {
  seen[x] = true;
  for (auto &y : h[x]) {
    if (seen[y]) continue;
    if (vc[y] != vc[x]) {
      g[r].push_back(y);
      g[y].push_back(r);
      pre(y, y);
    } else {
      pre(y, r);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &vc[i]);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    h[x].push_back(y);
    h[y].push_back(x);
  }
  memset(seen, 0, sizeof seen);
  pre(1, 1);
  for (int x = 1; x <= n; x++) dist[x] = -1;
  dist[1] = 0;
  dfs(1);
  pair<int, int> best = make_pair(-1ll, -1ll);
  for (int x = 1; x <= n; x++) chkmax(best, make_pair(dist[x], x));
  for (int x = 1; x <= n; x++) dist[x] = -1;
  dist[best.second] = 0;
  dfs(best.second);
  int diam = 0;
  for (int x = 1; x <= n; x++) chkmax(diam, dist[x]);
  int final = (1 + diam) / 2;
  printf("%d\n", final);
}
