#include <bits/stdc++.h>
using namespace std;
bool color[int(2e5 + 100)], c[int(2e5 + 100)];
vector<int> a[int(2e5 + 100)], newTree[int(2e5 + 100)];
int d[int(2e5 + 100)];
void compressed_dfs(int par, int u) {
  c[u] = true;
  for (auto v : a[u])
    if (!c[v]) {
      if (color[v] == color[par])
        compressed_dfs(par, v);
      else {
        newTree[par].push_back(v), newTree[v].push_back(par);
        compressed_dfs(v, v);
      }
    }
}
void dfs(int u, int h, int& res) {
  c[u] = true, d[u] = h;
  if (d[res] < h) res = u;
  for (auto v : newTree[u])
    if (!c[v]) dfs(v, h + 1, res);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", color + i);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u].push_back(v), a[v].push_back(u);
  }
  compressed_dfs(1, 1);
  memset(c, false, sizeof(c));
  int res1 = 1, res2;
  dfs(1, 0, res1);
  memset(c, false, sizeof(c));
  dfs(res1, 0, res2 = res1);
  printf("%d", (d[res2] + 1) >> 1);
}
