#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll N,u,v;
  cin>>N>>u>>v;
  u--;v--;
  vector<vector<ll>> T(N,vector<ll>());
  FOR(i,N-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  vector<ll> A(N),B(N,-1);
  vector<vector<ll>> stack{vector<ll>{v,0,-1}};
  while(!stack.empty()){
    vector<ll> t = stack.back();
    stack.pop_back();
    A[t[0]]=t[1];
    for(ll r:T[t[0]]){
      if(r==t[2])continue;
      stack.push_back(vector<ll>{r,t[1]+1,t[0]});
    }
  }
  stack.push_back(vector<ll>{u,0,-1});
  ll max_=0;
  while(!stack.empty()){
    vector<ll> t = stack.back();
    stack.pop_back();
    B[t[0]]=t[1];
    if(T[t[0]].size()!=1){//&&T[t[0]][0]==t[2]){
      if(max_<A[t[0]])max_=A[t[0]];
    }
    for(ll r:T[t[0]]){
      if(r==t[2])continue;
      if(A[r]<t[1])continue;
      stack.push_back(vector<ll>{r,t[1]+1,t[0]});
    }
  }
  /*
  for(auto a:A){
    cout<<a<<endl;
  }
  cout<<endl;
  for(auto a:B){
    cout<<a<<endl;
  }
  cout<<endl;
  */
  cout<<max_<<endl;
  return 0;
}
