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

const int N = 1e5+5;
int n;
vector<int> g[N];
vector<int> d;

void dfs(int x,int p,int dd){
    d[x] = dd;
    for(int to:g[x]){
        if(to == p)continue;
        dfs(to,x,dd+1);
    }
}

vector<int> dist(int x){
    d = vector<int>(n);
    dfs(x,-1,0);
    return d;
}

int main(){
    int u,v;
    cin>>n>>u>>v;
    --v,--u;
    for(int i = 0; i < n-1; i++){
        int a,b;cin>>a>>b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> d1 = dist(u);
    vector<int> d2 = dist(v);
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(d1[i]<d2[i]){
            ans = max(ans,d2[i]);
        }
    }
    cout<<ans-1;

}
