#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 123;
const long long INF = (long long)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
int n, c[N];
vector<int> g[N];
int mx, mx_pos;
void dfs(int x, int par = 0, int len = 0) {
  if (len > mx) {
    mx = len, mx_pos = x;
  }
  for (auto to : g[x]) {
    if (to == par) continue;
    if (c[x] == c[to])
      dfs(to, x, len);
    else
      dfs(to, x, len + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    g[a].push_back(b), g[b].push_back(a);
  }
  dfs(1);
  mx = 0;
  dfs(mx_pos);
  cout << (mx + 1) / 2;
  return 0;
}
