#include <bits/stdc++.h>
using namespace std;
bool color[200005], vis[200005];
int height[200005], dp[200005];
vector<vector<int> > v(200005);
int ans;
void dfs(int a) {
  vis[a] = true;
  dp[a] = 0;
  for (int i = 0; i < v[a].size(); i++) {
    if (!vis[v[a][i]]) {
      dfs(v[a][i]);
      ans = max(ans, dp[a] + dp[v[a][i]] + (color[a] != color[v[a][i]]));
      dp[a] = max(dp[a], dp[v[a][i]] + (color[a] != color[v[a][i]]));
    }
  }
  ans = max(ans, dp[a]);
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> color[i + 1];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1);
  cout << (ans + 1) / 2;
}
