#include <bits/stdc++.h>
using namespace std;
template <typename T>
void DEBUG(T e) {
  if (true == false) return;
  std::cout << e << std::endl;
}
template <typename T>
void DEBUG(const std::vector<T>& v) {
  if (true == false) return;
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T> >& vv) {
  if (true == false) return;
  for (const auto& v : vv) {
    DEBUG(v);
  }
}
template <class T, class X>
void DEBUG(X d, T e) {
  if (true == false) return;
  std::cout << d << " ";
  DEBUG(e);
};
template <class T>
void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    exit(0);
  }
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  return a > b && (a = b, true);
}
template <typename T>
using matrix = vector<vector<T> >;
static long long ANS = 0;
long long MODE = 0;
long long GV;
void DFS(long long V, long long depth, vector<vector<long long> >& GRAPH,
         vector<long long>& used, vector<long long>& path) {
  used[V] = 1;
  path[V] = depth;
  if (MODE == 0 && GV == V) depth = -1 * 1223372036854775807LL;
  for (long long i = 0; i < GRAPH[V].size(); i++) {
    long long check = 0;
    if (used[GRAPH[V][i]] == 0) {
      DFS(GRAPH[V][i], depth + 1, GRAPH, used, path);
      check = 1;
    }
    if (MODE == 0 && check == 0) path[V] = -1 * 1223372036854775807LL;
  }
  return;
}
void solve(void) {
  long long N;
  cin >> N;
  long long U, V;
  cin >> U >> V;
  U--;
  V--;
  GV = V;
  vector<vector<long long> > GRAPH(N);
  for (long long i = 0; i < N - 1; i++) {
    long long A, B;
    cin >> A >> B;
    A--;
    B--;
    GRAPH[A].push_back(B);
    GRAPH[B].push_back(A);
  }
  vector<long long> used(N, 0);
  vector<long long> path1(N, 0);
  vector<long long> path2(N, 0);
  DFS(U, 0, GRAPH, used, path1);
  vector<long long> used2(N, 0);
  MODE = 1;
  DFS(V, 0, GRAPH, used2, path2);
  long long ANS = 0;
  long long T_MAX = 0;
  long long T_MIN = 1223372036854775807LL;
  for (long long i = 0; i < N; i++) {
    if (path2[i] > path1[i]) chmax(T_MAX, path2[i]);
  }
  cout << T_MAX - 1 << endl;
  return;
}
int32_t main(int32_t argc, const char* argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  return 0;
}
