#include <bits/stdc++.h>
const unsigned long long inf = 1LL << 61;
const double eps = 1e-5;
using namespace std;
priority_queue<int, vector<int>, greater<int> > pq;
struct Node {
  int x, y;
};
struct cmp {
  bool operator()(Node a, Node b) {
    if (a.x == b.x) return a.y > b.y;
    return a.x > b.x;
  }
};
bool cmp(int a, int b) { return a > b; }
queue<int> q;
int dis[200010], fa[200010], vis[200010];
vector<int> v[200010];
pair<int, int> bfs(int u) {
  memset(vis, 0, sizeof(vis));
  dis[u] = 0;
  q.push(u);
  vis[u] = 1;
  int ans = u, Max = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < v[u].size(); i++) {
      int x = v[u][i];
      if (!vis[x]) {
        vis[x] = 1;
        if (fa[x] == fa[u]) {
          dis[x] = dis[u];
        } else
          dis[x] = dis[u] + 1;
        if (dis[x] > Max) {
          Max = dis[x];
          ans = x;
        }
        q.push(x);
      }
    }
  }
  return {ans, Max};
}
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> fa[i];
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cout << (bfs(bfs(1).first).second + 1) / 2 << endl;
  return 0;
}
