#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 2e5 + 10;
vector<int> g[MAX], h[MAX];
vector<int> C, A(MAX, -1);
void dfs(int fam, int v, int p) {
  A[v] = fam;
  for (int u : g[v]) {
    if (u == p) continue;
    if (!C[u]) dfs(fam, u, v);
  }
}
void dfs2(int fam, int v, int p) {
  A[v] = fam;
  for (int u : g[v]) {
    if (u == p) continue;
    if (!C[u]) {
      h[fam].push_back(A[u]);
      h[A[u]].push_back(fam);
    } else
      dfs2(fam, u, v);
  }
}
int BFS2(int v, int to) {
  queue<int> Q;
  Q.push(v);
  vector<int> D(MAX, -1);
  D[v] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto x : h[u]) {
      if (D[x] == -1) {
        D[x] = D[u] + 1;
        Q.push(x);
      }
    }
  }
  return D[to];
}
int BFS(int second) {
  queue<int> Q;
  Q.push(second);
  vector<int> Gone(MAX, 0);
  int last = second;
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    last = v;
    Gone[v] = 1;
    for (auto u : h[v]) {
      if (!Gone[u]) Q.push(u);
    }
  }
  return last;
}
void test_case() {
  int N;
  cin >> N;
  C.resize(MAX);
  for (int i = 0; i < N; i++) cin >> C[i];
  for (int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int fam = -1;
  for (int i = 0; i < N; i++) {
    if (!C[i] && A[i] == -1) dfs(++fam, i, -1);
  }
  for (int i = 0; i < N; i++) {
    if (C[i] && A[i] == -1) dfs2(++fam, i, -1);
  }
  int l = BFS(0);
  int r = BFS(l);
  int d = BFS2(r, l);
  cout << d / 2 << '\n';
}
int main() {
  int tt = 1;
  while (tt--) {
    test_case();
  }
  return 0;
}
