#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
int p[MX], kolor[MX], n;
int Find(int x) {
  if (p[x] == x) return x;
  return p[x] = Find(p[x]);
}
void Union(int a, int b) {
  a = Find(a);
  b = Find(b);
  p[a] = b;
}
vector<int> adj[MX];
vector<pair<int, int>> kraw;
bool vis[MX];
int res = 0;
int Dfs(int v) {
  vector<int> len;
  vis[v] = true;
  for (auto u : adj[v])
    if (!vis[u]) {
      len.push_back(Dfs(u) + 1);
    }
  sort(len.begin(), len.end());
  reverse(len.begin(), len.end());
  if (len.size() == 0) {
    return 0;
  }
  if (len.size() == 1) {
    res = max(res, len[0]);
    return len[0];
  }
  if (len.size() > 1) {
    res = max(res, len[0] + len[1]);
    return len[0];
  }
}
void Solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &kolor[i]);
    p[i] = i;
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (kolor[a] == kolor[b]) Union(a, b);
    kraw.push_back(make_pair(a, b));
  }
  for (auto e : kraw) {
    adj[Find(e.first)].push_back(Find(e.second));
    adj[Find(e.second)].push_back(Find(e.first));
  }
  Dfs(Find(1));
  printf("%d\n", res / 2 + res % 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Solve();
  return 0;
}
