#include <bits/stdc++.h>
using namespace std;
int n,u,v,ans;
vector<int> adj[100001];
int dist2[100001];
void dfs1(int node,int p,int dist){
    dist2[node]=dist;
    for (auto i:adj[node]){
        if (i==p) continue;
        dfs1(i,node,dist+1);
    }
}
void dfs(int node,int p,int dist){
    if (dist>dist2[node]){
        ans=max(ans,dist-1);
    }
    for (auto i:adj[node]){
        if (i==p) continue;
        dfs(i,node,dist+1);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>u>>v;
    for (int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs1(u,-1,0);
    dfs(v,-1,0);
    cout<<ans;
}
