#include <bits/stdc++.h>
using namespace std;
void read(long long a = 0) {
  freopen("in", "r", stdin);
  if (a) freopen("out", "w", stdout);
}
class dsu {
  vector<long long> par, sum;

 public:
  dsu(int n) {
    sum.assign(n, 1);
    for (int i = 0; i < n; i++) par.push_back(i);
  }
  int find_set(int a) { return par[a] == a ? a : par[a] = find_set(par[a]); }
  bool is_same(int a, int b) { return find_set(a) == find_set(b); }
  void union_sets(int a, int b) {
    long long n = find_set(a);
    long long m = find_set(b);
    if (n != m) {
      if (sum[n] > sum[m]) {
        par[m] = n;
        sum[n] += sum[m];
      } else {
        par[n] = m;
        sum[m] += sum[n];
      }
    }
  }
  long long get_sum(int a) { return sum[find_set(a)]; }
};
long long x[2 * 100009], y[2 * 100009];
long long a[2 * 100009];
bool vis[2 * 100009] = {};
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  dsu root(n + 1);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
    if (a[x[i]] == a[y[i]]) root.union_sets(x[i], y[i]);
  }
  vector<vector<long long> > ad(n + 1);
  for (int i = 0; i < n - 1; i++) {
    if (a[x[i]] != a[y[i]])
      ad[root.find_set(x[i])].push_back(root.find_set(y[i])),
          ad[root.find_set(y[i])].push_back(root.find_set(x[i]));
  }
  deque<long long> q;
  q.push_back(root.find_set(0));
  vis[root.find_set(0)] = 1;
  long long lv = 0;
  long long last;
  while (!q.empty()) {
    long long sz = q.size();
    while (sz--) {
      last = q.front();
      q.pop_front();
      for (int i = 0; i < ad[last].size(); i++) {
        long long u = ad[last][i];
        if (!vis[u]) {
          vis[u] = 1;
          q.push_back(u);
        }
      }
    }
  }
  q.clear();
  memset(vis, 0, sizeof(vis));
  q.push_back(last);
  vis[last] = 1;
  while (!q.empty()) {
    lv++;
    long long sz = q.size();
    while (sz--) {
      long long u = q.front();
      q.pop_front();
      for (int i = 0; i < ad[u].size(); i++) {
        long long v = ad[u][i];
        if (!vis[v]) {
          vis[v] = 1;
          q.push_back(v);
        }
      }
    }
  }
  cout << lv / 2;
}
