#include <bits/stdc++.h>
using namespace std;
string convertstring(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
const int N = 200002;
int n;
int U[N], V[N], c[N], comp[N];
int d[N], vis[N];
std::vector<int> v[N], gr[N];
int cmp = 1;
queue<int> q;
void dfs(int u, int par, int cmp) {
  comp[u] = cmp;
  for (int i = 0; i < v[u].size(); ++i) {
    int nx = v[u][i];
    if (nx != par) {
      if (c[nx] == c[u]) {
        dfs(nx, u, cmp);
      }
    }
  }
}
pair<int, int> bfs(int node) {
  d[node] = 0;
  memset(vis, 0, sizeof(vis));
  q.push(node);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 1;
    for (int i = 0; i < gr[u].size(); ++i) {
      int nx = gr[u][i];
      if (!vis[nx]) {
        d[nx] = d[u] + 1;
        q.push(nx);
      }
    }
  }
  pair<int, int> tmp = {-1, -1};
  for (int i = 1; i <= n; i++) {
    if (d[i] > tmp.second) {
      tmp = make_pair(i, d[i]);
    }
  }
  return tmp;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = (int)1; i < (int)n + 1; i++) scanf("%d", &c[i]);
  for (i = (int)0; i < (int)n - 1; i++) {
    scanf("%d", &U[i]);
    scanf("%d", &V[i]);
    v[U[i]].push_back(V[i]);
    v[V[i]].push_back(U[i]);
  }
  for (i = (int)1; i < (int)n + 1; i++) {
    if (comp[i] == 0) {
      dfs(i, -1, cmp);
      cmp++;
    }
  }
  for (i = (int)0; i < (int)n - 1; i++) {
    if (comp[U[i]] != comp[V[i]]) {
      gr[comp[U[i]]].push_back(comp[V[i]]);
      gr[comp[V[i]]].push_back(comp[U[i]]);
    }
  }
  pair<int, int> tmp = bfs(1);
  tmp = bfs(tmp.first);
  int ans = (tmp.second + 1) / 2;
  cout << ans;
  return 0;
}
