#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e5 + 10;
vector<vector<int> > g;
int color[MaxN];
int len[MaxN];
void cacl_len(int v, int cur_len) {
  len[v] = cur_len;
  for (int i = 0; i < (int)g[v].size(); ++i) {
    int to = g[v][i];
    if (len[to] != 0) {
      continue;
    }
    if (color[to] != color[v]) {
      cacl_len(to, cur_len + 1);
    } else {
      cacl_len(to, cur_len);
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> color[i];
  }
  int ans = n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cacl_len(0, 1);
  int max_len = 0;
  int max_len_v;
  for (int i = 0; i < n; ++i) {
    if (len[i] > max_len) {
      max_len = len[i];
      max_len_v = i;
    }
    len[i] = 0;
  }
  cacl_len(max_len_v, 1);
  max_len = 0;
  for (int i = 0; i < n; ++i) {
    if (len[i] > max_len) {
      max_len = len[i];
    }
  }
  cout << max_len / 2;
}
