#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
inline int read() {
  int s = 0;
  register bool neg = 0;
  register char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-');
  for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), c = getchar())
    ;
  s = (neg ? -s : s);
  return s;
}
int a, b, mx[N + 10], mxx[N + 10];
bool s[N + 10];
vector<int> st[N + 10];
inline void dfs(int n, int fa) {
  mx[n] = mxx[n] = 1;
  for (int i = 0; i < st[n].size(); i++) {
    int v = st[n][i];
    if (v == fa) continue;
    dfs(v, n);
    if (mx[n] < mx[v] + (s[v] ^ s[n])) {
      mxx[n] = mx[n];
      mx[n] = mx[v] + (s[v] ^ s[n]);
    } else if (mxx[n] < mx[v] + (s[v] ^ s[n]))
      mxx[n] = mx[v] + (s[v] ^ s[n]);
  }
}
signed main() {
  a = read();
  for (int i = 1; i <= a; i++) s[i] = read();
  int x, y;
  for (int i = 1; i < a; i++) {
    x = read();
    y = read();
    st[x].push_back(y);
    st[y].push_back(x);
  }
  dfs(1, 0);
  int ans = 0;
  for (int i = 1; i <= a; i++) ans = max(ans, mx[i] + mxx[i] - 1);
  printf("%d", (ans) / 2);
  return 0;
}
