#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int n, c[N], color[N], dp[N], ans, n1;
vector<int> g[N], g1[N];
void dfs(int v, int cur) {
  color[v] = cur;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (!color[to] && c[v] == c[to]) dfs(to, cur);
  }
}
void dfs1(int v, int p = -1) {
  int mx1 = 0, mx2 = 0;
  for (int i = 0; i < g1[v].size(); i++) {
    int to = g1[v][i];
    if (to == p) continue;
    dfs1(to, v);
    mx2 = max(mx2, dp[to] + 1);
    if (mx2 > mx1) swap(mx2, mx1);
  }
  dp[v] = mx1;
  ans = max(ans, mx1 + mx2);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[y].push_back(x);
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (!color[i]) {
      dfs(i, ++n1);
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < g[i].size(); j++) {
      int to = g[i][j];
      if (color[i] != color[to]) g1[color[i]].push_back(color[to]);
    }
  dfs1(1);
  printf("%d", (ans + 1) / 2);
  return 0;
}
