#include <bits/stdc++.h>
using namespace std;
int n, arr[200009], k;
vector<int> graph[200009];
bool vis[200009];
vector<int> graph2[200009];
void dfs(int i, int prev) {
  if (vis[i]) return;
  vis[i] = 1;
  if (arr[i] != arr[prev]) {
    graph2[i].push_back(prev);
    graph2[prev].push_back(i);
    prev = i;
  }
  for (int f = 0; f < graph[i].size(); f++) dfs(graph[i][f], prev);
}
pair<int, int> dfs1(int i, int prev) {
  pair<int, int> ret = {0, 0};
  for (int f = 0; f < graph2[i].size(); f++)
    if (graph2[i][f] != prev) ret = max(ret, dfs1(graph2[i][f], i));
  ret.first++;
  if (ret.second == 0) ret.second = i;
  return ret;
}
int main() {
  int a, b;
  scanf("%d", &n);
  for (int f = 1; f <= n; f++) scanf("%d", &arr[f]);
  for (int f = 0; f < n - 1; f++) {
    scanf("%d%d", &a, &b);
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(1, 1);
  int i = 1, x;
  for (int f = 0; f < 4; f++) {
    pair<int, int> temp = dfs1(i, i);
    i = temp.second;
    x = temp.first;
  }
  cout << x / 2 << endl;
}
