#include<bits/stdc++.h> 
using namespace std;
 
#define ll long long int
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 998244353
#define ll_MAX 19223372036859
#define endl "\n"
inline ll absdiff(ll a,ll b){ return (a>b)?a-b:b-a;}
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

int main()
{
    fast
    ll q;q = 1;
    // cin>>q;
    for (ll t = 0; t < q; ++t)
    {
        ll n,u,v;cin>>n>>u>>v;
        vector<ll> AdjL[n+1];
        for(ll i=1;i<n;++i){
            ll x,y;cin>>x>>y;
            AdjL[x].pb(y);
            AdjL[y].pb(x);
        }

        ll dis1[n+1];
        ll vis1[n+1]{};
        fill_n(dis1,n+1,INT_MAX);
        queue<ll> Q;
        Q.push(u);
        dis1[u]=0;
        vis1[u]=1;
        while(!Q.empty()){
            ll temp=Q.front();
            Q.pop();
            if(temp==v) continue;
            for(ll i=0;i<AdjL[temp].size();++i){
                if(!vis1[AdjL[temp][i]]){
                    Q.push(AdjL[temp][i]);
                    vis1[AdjL[temp][i]]=1;
                    dis1[AdjL[temp][i]]=dis1[temp]+1;
                }
            }
        }

        ll dis2[n + 1];
        ll vis2[n + 1]{};

        Q.push(v);
        dis2[v] = 0;
        vis2[v] = 1;
        while (!Q.empty())
        {
            ll temp = Q.front();
            Q.pop();
            for (ll i = 0; i < AdjL[temp].size(); ++i)
            {
                if (!vis2[AdjL[temp][i]])
                {
                    Q.push(AdjL[temp][i]);
                    vis2[AdjL[temp][i]] = 1;
                    dis2[AdjL[temp][i]] = dis2[temp] + 1;
                }
            }
        }

        ll ans=INT_MIN;
        for(ll i=1;i<=n;++i){
            if(dis1[i]==INT_MAX) continue;

            ans=max(ans,dis2[i]-1);
        }

        cout<<ans;
    }   
    return 0;
}   