#include <bits/stdc++.h>
using namespace std;
int n;
struct Edge {
  int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};
vector<Edge> edges;
struct Data {
  int tov, next;
} data[200005 * 2];
int head[200005];
int tot;
void insert(int a, int b) {
  tot++;
  data[tot].tov = b;
  data[tot].next = head[a];
  head[a] = tot;
}
int vis[200005];
int kind[200005];
int belong[200005];
void dfs(int x, int whe) {
  if (vis[x]) return;
  vis[x] = 1;
  belong[x] = whe;
  for (int k = head[x]; k; k = data[k].next) {
    if (kind[data[k].tov] == kind[x]) {
      dfs(data[k].tov, whe);
    }
  }
}
int max1[200005];
int max2[200005];
void update(int x, int to) {
  if (max1[to] + 1 > max1[x]) {
    max2[x] = max1[x];
    max1[x] = max1[to] + 1;
  } else if (max1[to] + 1 == max1[x]) {
    max2[x] = max1[to] + 1;
  } else if (max1[to] + 1 < max1[x]) {
    if (max1[to] + 1 > max2[x]) {
      max2[x] = max1[to] + 1;
    }
  }
}
void find(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  for (int k = head[x]; k; k = data[k].next)
    if (!vis[data[k].tov]) {
      find(data[k].tov);
      update(x, data[k].tov);
    }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> kind[i];
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    insert(a, b);
    insert(b, a);
    edges.push_back(Edge(a, b));
  }
  int tt = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      dfs(i, ++tt);
    }
  memset(data, 0, sizeof(data));
  memset(head, 0, sizeof(head));
  tot = 0;
  n = tt;
  for (int i = 0; i < edges.size(); i++) {
    Edge &e = edges[i];
    if (belong[e.from] == belong[e.to]) continue;
    insert(belong[e.from], belong[e.to]);
    insert(belong[e.to], belong[e.from]);
  }
  memset(vis, 0, sizeof(vis));
  find(1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, max1[i] + max2[i]);
  }
  cout << (ans + 1) / 2 << endl;
  return 0;
}
