#include <bits/stdc++.h>
using namespace std;
void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
const int N = 2 * (int)1e5 + 10;
int n, c[N], p[N];
vector<int> child[N];
bool vis[N];
vector<int> now[N];
map<pair<int, int>, bool> ist;
int Find(int x) {
  if (x == p[x]) return x;
  return p[x] = Find(p[x]);
}
void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  p[x] = y;
}
void dfs(int v) {
  vis[v] = true;
  for (auto dz : child[v])
    if (!vis[dz]) {
      if (c[dz] == c[v]) Union(dz, v);
      dfs(dz);
    }
}
void dfs2(int v) {
  vis[v] = true;
  for (auto dz : child[v])
    if (!vis[dz]) {
      if (c[Find(dz)] != c[Find(v)] &&
          ist.find({Find(dz), Find(v)}) == ist.end()) {
        int x = Find(v);
        int y = Find(dz);
        now[x].push_back(y);
        now[y].push_back(x);
        ist[{x, y}] = ist[{y, x}] = true;
      }
      dfs2(dz);
    }
}
int v1, wys = -1;
int odl = 0;
void dfs3(int v, int h) {
  vis[v] = true;
  if (h > wys) {
    v1 = v;
    wys = h;
  }
  for (auto dz : now[v]) {
    if (!vis[dz]) dfs3(dz, h + 1);
  }
}
void dfs4(int v, int h) {
  vis[v] = true;
  odl = max(odl, h);
  for (auto dz : now[v]) {
    if (!vis[dz]) dfs4(dz, h + 1);
  }
}
int main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
    cin >> c[i];
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    child[x].push_back(y);
    child[y].push_back(x);
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) vis[i] = false;
  dfs2(1);
  for (int i = 1; i <= n; ++i) vis[i] = false;
  for (int i = 1; i <= n; ++i) {
    if (now[i].size() > 0) {
      dfs3(i, 0);
      for (int i = 1; i <= n; ++i) vis[i] = false;
      dfs4(v1, 0);
      cout << (odl + 1) / 2 << "\n";
      return 0;
    }
  }
  cout << "0\n";
}
