#include <bits/stdc++.h>
using namespace std;
vector<int> g[201000];
bool vis[201000];
int color[201000];
int id;
pair<int, int> D;
void dfs(int x, int d) {
  vis[x] = true;
  if (D < make_pair(d, x)) D = make_pair(d, x);
  for (int i = 0; i < g[x].size(); i++)
    if (!vis[g[x][i]]) dfs(g[x][i], d + (color[x] != color[g[x][i]]));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &color[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(vis, 0, sizeof(vis));
  D = make_pair(0, 1);
  dfs(1, 0);
  memset(vis, 0, sizeof(vis));
  dfs(D.second, 1);
  printf("%d\n", D.first / 2);
  return 0;
}
