#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c;
  int positive = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') positive = 0;
  do x = x * 10 + c - '0';
  while (isdigit(c = getchar()));
  if (!positive) x = -x;
}
template <typename T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
const int maxn = 200010;
int n;
int c[maxn];
vector<int> a[maxn], ga[maxn];
int com[maxn];
int C;
int ans;
int f[maxn];
void input() {
  read(n);
  for (int i = (1), _b = (n); i <= _b; i++) read(c[i]);
  for (int i = (1), _b = (n); i < _b; i++) {
    int u, v;
    read(u);
    read(v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
}
void dfs(int u) {
  com[u] = C;
  for (int i = (0), _b = (int((a[u]).size())); i < _b; i++) {
    int v = a[u][i];
    if (com[v] || c[v] != c[u]) continue;
    dfs(v);
  }
}
void dfs2(int u, int pa = -1) {
  int mx = 0, mx2 = 0;
  for (int i = (0), _b = (int((ga[u]).size())); i < _b; i++) {
    int v = ga[u][i];
    if (v == pa) continue;
    dfs2(v, u);
    mx2 = max(mx2, f[v]);
    if (mx < mx2) swap(mx, mx2);
  }
  ans = max(ans, (mx + mx2 + 1) / 2);
  f[u] = mx + 1;
}
void solve() {
  for (int i = (1), _b = (n); i <= _b; i++)
    if (!com[i]) C++, dfs(i);
  for (int u = (1), _b = (n); u <= _b; u++) {
    for (int i = (0), _b = (int((a[u]).size())); i < _b; i++) {
      int v = a[u][i];
      if (com[u] != com[v]) ga[com[u]].push_back(com[v]);
    }
  }
  dfs2(1);
}
void output() { write(ans); }
int main() {
  clock_t timestart, timeend;
  timestart = clock();
  input();
  solve();
  output();
  timeend = clock();
  return 0;
}
