#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
void Mark(int v, int c, const Graph& gr, const vector<int>& color,
          vector<int>& component) {
  component[v] = c;
  for (int u : gr[v]) {
    if (component[u] != -1) {
      continue;
    }
    if (color[u] != color[v]) {
      continue;
    }
    Mark(u, c, gr, color, component);
  }
}
Graph Condensate(const Graph& gr, const vector<int>& color) {
  int N = gr.size();
  vector<int> component(N, -1);
  int c = 0;
  for (int i = 0; i < N; ++i) {
    if (component[i] != -1) {
      continue;
    }
    Mark(i, c, gr, color, component);
    ++c;
  }
  set<pair<int, int>> used;
  Graph result(c);
  for (int v = 0; v < N; ++v) {
    for (int u : gr[v]) {
      if (color[v] == color[u]) {
        continue;
      }
      assert(component[v] != component[u]);
      int a = component[v], b = component[u];
      if (a > b) {
        swap(a, b);
      }
      if (used.count({a, b})) {
        continue;
      }
      used.insert({a, b});
      result[a].push_back(b);
      result[b].push_back(a);
    }
  }
  return result;
}
vector<int> Dist(int v, const Graph& gr) {
  vector<int> H(gr.size(), -1);
  queue<int> Q;
  H[v] = 0;
  Q.push(v);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i : gr[u]) {
      if (H[i] == -1) {
        H[i] = H[u] + 1;
        Q.push(i);
      }
    }
  }
  return H;
}
int Diam(const Graph& gr) {
  auto H1 = Dist(0, gr);
  int v = max_element(H1.begin(), H1.end()) - H1.begin();
  auto H2 = Dist(v, gr);
  return *max_element(H2.begin(), H2.end());
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> color(N);
  for (auto& c : color) {
    cin >> c;
  }
  Graph gr(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  auto c_gr = Condensate(gr, color);
  cout << (Diam(c_gr) + 1) / 2 << '\n';
  return 0;
}
