#include <bits/stdc++.h>
std::vector<std::vector<int> > AB;
std::vector<int> min_dist;
std::vector<int> min_route;
int Ust;
int max_dist = 0;
int pre_center;
void route1(int pos, int dist, std::vector<int> route, int pre_pos) {
  min_dist[pos] = dist;
  if (pos == Ust) {
    min_route = route;
  }
  for (int i = 0; i < AB[pos].size(); i++) {
    if (AB[pos][i] != pre_pos) {
      std::vector<int> route_tmp = route;
      route_tmp.push_back(AB[pos][i]);
      route1(AB[pos][i], dist + 1, route_tmp, pos);
    }
  }
}
void route2(int pos, int dist, int pre_pos) {
  min_dist[pos] = dist;
  if (max_dist < dist) {
    max_dist = dist;
  }
  for (int i = 0; i < AB[pos].size(); i++) {
    if (AB[pos][i] != pre_pos && AB[pos][i] != pre_center) {
      route2(AB[pos][i], dist + 1, pos);
    }
  }
}
int main() {
  int N, u, v;
  std::cin >> N >> u >> v;
  u--;
  v--;
  Ust = u;
  AB.resize(N);
  for (int i = 1; i < N; i++) {
    int tmpa, tmpb;
    std::cin >> tmpa >> tmpb;
    tmpa--;
    tmpb--;
    AB[tmpa].push_back(tmpb);
    AB[tmpb].push_back(tmpa);
  }
  min_dist.assign(N, 1e9);
  route1(v, 0, std::vector<int>(1, v), -1);
  int center = (min_route.size() % 2 == 0)
                   ? min_route[min_route.size() / 2]
                   : min_route[min_route.size() / 2 + 1];
  pre_center = (min_route.size() % 2 == 0) ? min_route[min_route.size() / 2 - 1]
                                           : min_route[min_route.size() / 2];
  int center_dist = (min_route.size() % 2 == 0) ? min_route.size() / 2
                                                : min_route.size() / 2 + 1;
  min_dist.assign(N, 1e9);
  route2(center, 0, -1);
  std::cout << center_dist + max_dist - 1 << std::endl;
  return 0;
}
