#include<bits/stdc++.h>
using namespace std;

int n;
const int N=1e+5+5;
vector<int> adj[N];
int dist1[N],dist2[N];
int ans=0;
void dfs(int v,int p,int d)
{
    dist1[v]=d;
    for(auto it:adj[v])
        if(it!=p)
            dfs(it,v,d+1);
}
void dfs2(int v,int p,int d)
{
    dist2[v]=d;
    if(dist1[v]<=d)
        return;
    for(auto it:adj[v])
    {
        if(it!=p)
        {
            dfs2(it,v,d+1);
        }
    }
    if(adj[v].size()==1)
        ans=max(ans,dist1[v]-1);
}
int main()
{
    int v,u;
    cin>>n>>v>>u;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(u,u,0);
    dfs2(v,v,0);
    cout<<ans;
}