#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define N                300005
#define inf              999999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type, less<int >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//________________________________________________________________________________________________________________
bool cmp(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.first>b.first) return true;
    if(a.first<b.first) return false;
    if(a.second<b.second) return true;
    else return false;

}
bool ok=false;
ll cnt[N],vis[N],vis1[N],dp[N];
ll t,n,m,x,r,y,z,mod=998244353,ans=0,u,v;
vector<ll>v1[N],v2;
string s,s1;
int dfs(int p)
{
    vis[p]=1;
    if(p==v)
    {
        v2.pb(v);
        return 1;
    }
    for(auto x1 : v1[p])
    {
        if(!vis[x1])
        {
            x=dfs(x1);
            if(x)
            {
                v2.pb(p);
                return 1;
            }
        }
    }
    return 0;
}
void dfs1(int p)
{
    vis1[p]=1;
    vis[p]=1;
    for(auto x1 : v1[p])
    {
        if(!vis[x1]) dfs1(x1);
    }
}
void dfs2(int p)
{
    vis[p]=1;
    for(auto x1 : v1[p])
    {
        if(!vis[x1])
        {
            dp[x1]=dp[p]+1;
            dfs2(x1);
        }
    }
}
int main()
{
    cin>>n>>u>>v;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        v1[x].pb(y);
        v1[y].pb(x);
    }
    x=dfs(u);
    //for(auto x1 : v2) cout<<x1<<endl;
    if(v2.size()==2 && v1[u].size()==1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(v2.size()==3 && v1[u].size()==1)
    {
        cout<<1<<endl;
        return 0;
    }
    z=(ll)(v2.size())/2LL;
    z=v2[z-1];
    mem(vis,0);
    vis[z]=1;
    dfs1(u);
    mem(vis,0);
    dfs2(v);
    x=0;
    for(int i=1;i<=n;i++)
    {
        if(i!=v && dp[i] && vis1[i])
        {
            x=max(x,dp[i]);
        }
    }
    cout<<x-1<<endl;
    return 0;
}


Measured memory_bytes: 21488