#include <bits/stdc++.h>
using namespace std;
const int MAX = (int(2E5) + 5);
struct Edge {
  int to;
  int prev;
};
Edge edges[(MAX << 1)];
int head[MAX];
int cur = -1;
int dp[MAX];
int color[MAX];
void dfs(int now, int far) {
  for (int i = head[now]; ~i; i = edges[i].prev) {
    if (edges[i].to != far) {
      if (color[edges[i].to] != color[now]) {
        dp[edges[i].to] = dp[now] + 1;
        dfs(edges[i].to, now);
      } else {
        dp[edges[i].to] = dp[now];
        dfs(edges[i].to, now);
      }
    }
  }
  return;
}
void addEdge(int a, int b) {
  cur++;
  edges[cur].to = b;
  edges[cur].prev = head[a];
  head[a] = cur;
  return;
}
void initialize(int n) {
  for (int i = 1; i <= n; i++) {
    scanf("%d", color + i);
  }
  memset(head, -1, sizeof(head));
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    addEdge(a, b);
    addEdge(b, a);
  }
  return;
}
int main() {
  int n;
  cin >> n;
  initialize(n);
  int maxposition = 1, maxlenth = 0;
  dp[1] = 0;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (dp[i] > maxlenth) {
      maxposition = i;
      maxlenth = dp[i];
    }
  }
  maxlenth = 0;
  dp[maxposition] = 0;
  dfs(maxposition, 0);
  for (int i = 1; i <= n; i++) {
    if (dp[i] > maxlenth) {
      maxposition = i;
      maxlenth = dp[i];
    }
  }
  printf("%d\n", ((maxlenth + 1) >> 1));
  return 0;
}
