#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = (1uLL << 63) - 1;
const int mod = 1000000007;
const int N = 1e5 + 5;
const double Pi = acos(-1.0);
const int maxn = 2e5 + 5;
int col[maxn];
vector<int> G[maxn];
int d = -1, h;
void dfs(int fa, int u, int num) {
  if (num > d) {
    d = num;
    h = u;
  }
  for (int v : G[u]) {
    if (v == fa) continue;
    dfs(u, v, num + (col[u] ^ col[v]));
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &col[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(-1, 1, 1);
  dfs(-1, h, 1);
  cout << d / 2 << endl;
}
