#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph, new_graph;
vector<int> vis, col;
void dfs(int start, int num) {
  vis[start] = num;
  for (auto i : graph[start]) {
    if (vis[i] == 0 && col[i] == col[start]) {
      dfs(i, num);
    }
  }
}
vector<int> dist;
void DFS(int start) {
  vis[start] = 1;
  for (auto i : new_graph[start]) {
    if (vis[i] == 0) {
      dist[i] = dist[start] + 1;
      DFS(i);
    }
  }
}
int find(int n) {
  vis.clear();
  vis.assign(n, 0);
  dist.assign(n, 0);
  DFS(1);
  int i, mx = -1, v;
  for (i = 1; i < n; i++) {
    if (dist[i] > mx) {
      mx = dist[i];
      v = i;
    }
  }
  dist.assign(n, 0);
  vis.assign(n, 0);
  DFS(v);
  mx = 0;
  for (i = 1; i < n; i++) {
    mx = max(mx, dist[i]);
  }
  return mx;
}
int main() {
  int n, i, x, y;
  scanf("%d", &n);
  graph.assign(n + 1, vector<int>());
  vis.assign(n + 1, 0);
  col.resize(n + 1);
  for (i = 1; i <= n; i++) scanf("%d", &col[i]);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  int num = 1;
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      dfs(i, num);
      num++;
    }
  }
  new_graph.assign(num, vector<int>());
  for (i = 1; i <= n; i++) {
    for (auto j : graph[i]) {
      if (vis[i] != vis[j]) {
        new_graph[vis[i]].push_back(vis[j]);
      }
    }
  }
  int dia = find(num);
  printf("%d", (dia + 1) / 2);
}
