#include <bits/stdc++.h>
using namespace std;
vector<int> c;
vector<vector<int>> g;
int ans = 1;
int dfs(int i, int p) {
  int a = 1, b = 1;
  for (int j : g[i]) {
    if (j == p) continue;
    int k = dfs(j, i) + (c[i] != c[j]);
    if (k > a)
      b = a, a = k;
    else if (k > b)
      b = k;
  }
  ans = max(ans, a + b - 1);
  return a;
}
int main() {
  int n;
  cin >> n;
  c.resize(n), g.resize(n);
  for (int i = 0; i < n; ++i) cin >> c[i];
  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);
  }
  dfs(0, -1);
  cout << ans / 2;
}
