#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<vector<int>> G;
vector<ll> t_dis, a_dis;

void t_dfs(int x,ll d){
    t_dis[x]=d;
    for(int y:G[x]){
        if(t_dis[y]==INF)t_dfs(y,d+1);
    }
}

void a_dfs(int x, ll d) {
    a_dis[x] = d;
    for(int y : G[x]) {
        if(a_dis[y] == INF) a_dfs(y, d + 1);
    }
}

int main() {
    ll n,a,b,t;
    cin >> n >> t >> a;
    G.resize(n+1);
    t_dis.resize(n+1,INF);
    a_dis.resize(n+1,INF);
    for(ll i=0;i<n-1;i++){
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    t_dfs(t,0ll);
    a_dfs(a,0ll);
    ll ret = 0;
    for(int i=1;i<=n;i++){
        if(t_dis[i]<a_dis[i])ret=max(ret,a_dis[i]);
    }
    cout << ret-1 << endl;
    return 0;
}