#include <bits/stdc++.h>
using namespace std;
void dfs(int start, vector<int> &v, queue<int> &myq, vector<int> A[],
         bool visited[], int color[]) {
  visited[start] = true;
  for (int i = 0; i < A[start].size(); i++) {
    int n = A[start][i];
    if (visited[n] == false && color[n] != color[start]) {
      v.push_back(n);
      myq.push(n);
    } else if (visited[n] == false) {
      dfs(n, v, myq, A, visited, color);
    }
  }
  return;
}
void calc(unordered_map<int, vector<int>> &A, bool visited[], int start,
          unordered_map<int, pair<int, int>> &dp) {
  if (A[start].size() == 0) {
    dp.insert(make_pair(start, make_pair(0, 0)));
  } else {
    for (int i = 0; i < A[start].size(); i++) {
      calc(A, visited, A[start][i], dp);
    }
    int max1 = -1, max2 = -1;
    for (int i = 0; i < A[start].size(); i++) {
      int n = A[start][i];
      if (dp[n].first > max1) {
        max2 = max1;
        max1 = dp[n].first;
      } else if (dp[n].first > max2) {
        max2 = dp[n].first;
      }
    }
    if (max2 != -1)
      dp.insert(make_pair(start, make_pair(max1 + 1, max1 + max2 + 2)));
    else
      dp.insert(make_pair(start, make_pair(max1 + 1, max1 + 1)));
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> adjacencyList[n];
  int color[n];
  for (int i = 0; i < n; i++) {
    cin >> color[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adjacencyList[u].push_back(v);
    adjacencyList[v].push_back(u);
  }
  bool visited[n];
  for (int i = 0; i < n; i++) visited[i] = false;
  unordered_map<int, vector<int>> newList;
  queue<int> myq;
  myq.push(0);
  while (myq.empty() == false) {
    int i = myq.front();
    myq.pop();
    if (!visited[i]) {
      vector<int> adjacent;
      dfs(i, adjacent, myq, adjacencyList, visited, color);
      newList.insert(make_pair(i, adjacent));
    }
  }
  for (int i = 0; i < n; i++) {
    visited[i] = false;
  }
  unordered_map<int, pair<int, int>> dp;
  calc(newList, visited, 0, dp);
  unordered_map<int, pair<int, int>>::iterator itr = dp.begin();
  int ans = 0;
  while (itr != dp.end()) {
    ans = max((itr->second).second, ans);
    itr++;
  }
  cout << (ans + 1) / 2 << endl;
}
