#include <bits/stdc++.h>
using namespace std;
bool compare_F(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second > b.second;
  }
}
bool compare_S(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second > b.second;
  } else {
    return a.first > b.first;
  }
}
template <typename T>
void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr != A.end(); ++itr) {
    cin >> *itr;
  }
}
template <typename T>
void ArrayPut(vector<T> &A) {
  for (auto itr = A.begin(); itr != A.end(); ++itr) {
    cout << *itr << " ";
  }
  cout << endl;
}
using Graph = vector<vector<uint32_t>>;
vector<bool> seen;
vector<uint32_t> dis, A_dis, T_dis;
void dfs(Graph &G, uint32_t v) {
  seen[v] = true;
  for (auto itr = G[v].begin(); itr != G[v].end(); ++itr) {
    if (seen[*itr]) continue;
    dis[*itr] = dis[v] + 1;
    dfs(G, *itr);
  }
}
int main() {
  uint32_t N, u, v;
  cin >> N >> u >> v;
  Graph G(N);
  for (uint32_t i = 0; i < (N - 1); ++i) {
    uint32_t a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  seen.assign(N, false);
  dis.assign(N, 0);
  dfs(G, u - 1);
  T_dis = dis;
  dis.assign(N, 0);
  seen.assign(N, false);
  A_dis.assign(N, 0);
  dfs(G, v - 1);
  A_dis = dis;
  priority_queue<uint32_t> Que;
  for (uint32_t i = 0; i < N; ++i) {
    if (A_dis[i] > T_dis[i]) Que.push(T_dis[i]);
  }
  cout << Que.top();
  return 0;
}
