#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, c[maxn];
vector<int> E[maxn];
pair<int, int> dfs(int x, int fa, int deep) {
  pair<int, int> tmp = make_pair(deep, x);
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (v == fa) continue;
    if (c[v] != c[x])
      tmp = max(tmp, dfs(v, x, deep + 1));
    else
      tmp = max(tmp, dfs(v, x, deep));
  }
  return tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[a].push_back(b);
    E[b].push_back(a);
  }
  pair<int, int> tmp = dfs(1, -1, 0);
  tmp = dfs(tmp.second, -1, 0);
  cout << (tmp.first + 1) / 2 << endl;
}
