#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define MP make_pair
#define int ll int

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef map<int,int>MII;
typedef vector<int> VI;
const int MAX = 1e4 + 5;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//int modInverse(int a, int m) { power(a, m-2);} //gcd(a,m)=1 
/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int root(int x){return x==f[x]?x:f[x]=root(f[x]);}
bool vis[1000000]={false},vis2[1000000]={false};
vector<VI>adj;VI height(1000000,0);VI depth(1000000,0);int ans=0;
void dfs(int v,int h) {
        vis[v] = true;
        for(auto it:adj[v])
        {
            if(vis[it]==false)
            {
                height[it]=h;
                dfs(it,h+1);
                depth[v]=max(depth[v],depth[it]+1);
            }
        }
        
    }
    
void dfs2(int v,int k)
{
    vis2[v]=true;
    if(height[v]>k)
    ans=max(ans,depth[v]+height[v]-k);
    
    for(auto it:adj[v])
    {
        if(vis2[it]==false)
        {
            dfs2(it,k+2);
        }
    }
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int n,u,v;
    cin>>n>>u>>v;adj.resize(n+1);
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    if(v==u)
    {
        cout<<"0"<<endl;return 0;
    }
    dfs(v,0);
    dfs2(u,0);
    cout<<ans<<endl;
}


return 0;
}



