#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
vector<int> adj[N], adjx[N];
int p[N], c[N];
int find(int x) { return p[x] = (p[x] != x) ? find(p[x]) : p[x]; }
void join(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    p[a] = b;
  }
}
int dp[N];
int f(int u, int p) {
  int mx1 = 0, mx2 = 0, res = 0;
  for (int v : adjx[u])
    if (v != p) {
      res = max(res, f(v, u));
      if (dp[v] > mx1) {
        mx2 = mx1;
        mx1 = dp[v];
      } else if (dp[v] > mx2) {
        mx2 = dp[v];
      }
    }
  dp[u] = 1 + mx1;
  return max(res, 1 + mx1 + mx2);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i], p[i] = i;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    if (c[u] == c[v]) join(u, v);
  }
  for (int i = 1; i <= n; i++) {
    for (int j : adj[i]) {
      if (find(i) != find(j)) adjx[find(i)].push_back(find(j));
    }
  }
  cout << f(find(1), 0) / 2 << endl;
}
