#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a < b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  while (b != 0) {
    long long int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
const int N = 200005;
void judge() {}
struct myhash {
  static uint64_t fxn(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return fxn(x + FIXED_RANDOM);
  }
};
long long int color[N + 1];
vector<vector<long long int>> g(N + 1);
long long int ans = 1;
long long int node = 1;
void dfs(long long int par, long long int source, long long int nc) {
  if (nc > ans) {
    ans = nc, node = source;
  }
  for (auto x : g[source]) {
    if (x != par) {
      if (color[x] != color[source])
        dfs(source, x, nc + 1);
      else
        dfs(source, x, nc);
    }
  }
}
void solve(int tc) {
  long long int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> color[i];
  color[0] = color[1];
  for (int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(0, 1, 1);
  dfs(0, node, 1);
  cout << ans / 2;
  cout << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  judge();
  int T = 1;
  for (int tc = 1; tc <= T; tc++) {
    solve(tc);
  }
  return 0;
}
