#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    ll x,y;
    cin>>x>>y;
    vector<ll> adj[n+1];
    ll dis[n+1];
    for(ll i=0;i<n-1;++i)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    dis[y]=0;
    queue<ll> q;
    q.push(y);
    ll vis[n+1]={0};
    vis[y]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        for(auto u:adj[v])
        {
            if(vis[u]){continue;}
            vis[u]=1;
            q.push(u);
            dis[u]=1+dis[v];
        }
    }

    ll ans=0;
    for(ll i=0;i<=n;++i){vis[i]=0;}
    ll time[n+1]={0};
    q.push(x);
    vis[x]=1;
    time[x]=0;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        for(auto u:adj[v])
        {
            if(vis[u]){continue;}
            time[u]=1+time[v];
            vis[u]=1;
            if(time[u]>dis[u]){continue;}
            if(time[u]==dis[u]){ans=max(ans,time[u]);continue;}
            q.push(u);
            ans=max(ans,min(time[u],dis[u]));
        }
    }
    cout<<ans;

    return (0);
}
