#include <bits/stdc++.h>
using namespace std;
const int MAX = 212345;
int color[MAX], n, vis[MAX], top;
vector<int> raw_edge[MAX], edge[MAX];
void dfs(int u) {
  vis[u] = top;
  for (int i = 0; i < raw_edge[u].size(); i++) {
    int v = raw_edge[u][i];
    if (!vis[v] && color[u] == color[v]) {
      dfs(v);
    } else if (vis[v] && color[u] != color[v]) {
      edge[top].push_back(vis[v]);
      edge[vis[v]].push_back(top);
    }
  }
}
void build() {
  top = 1;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      top++;
    }
  }
}
int bfs(int u) {
  memset(vis, 0, sizeof(vis));
  queue<int> q;
  q.push(u);
  vis[u] = 1;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i];
      if (!vis[v]) {
        vis[v] = vis[u] + 1;
        q.push(v);
      }
    }
  }
  int pos = 1;
  for (int i = 1; i < top; i++) {
    if (vis[i] > vis[pos]) pos = i;
  }
  return pos;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> color[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    raw_edge[u].push_back(v);
    raw_edge[v].push_back(u);
  }
  build();
  int x = bfs(1);
  printf("%d\n", vis[bfs(x)] / 2);
}
