#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const ll INF = 2e9+10;

struct edge{
    int to, next;
}G[maxn << 1];
int tot, head[maxn];
void addEdge(int u, int v){G[tot] = {v, head[u]};head[u] = tot++;};
int n, s, t, vis[2][maxn];
void dfs(int u, int fa, int x){
    for(int i = head[u];i != -1;i = G[i].next)
        if(G[i].to != fa)
            vis[x][G[i].to] = vis[x][u] + 1, dfs(G[i].to, u, x);
}
int main(){
    #ifdef Irene
    freopen("in.txt", "r", stdin);
    #endif // Irene
    ios_base::sync_with_stdio(false);

    cin >> n >> s >> t;
    int u, v;
    for(int i = 1;i <= n;i++)head[i] = -1;
    for(int i = 1;i < n;i++){
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }
    dfs(s, -1, 0);
    dfs(t, -1, 1);
    for(int i = 1;i <= n;i++)
        if(vis[0][i] < vis[1][i])
            ans = max(ans, vis[1][i] - 1);        
    cout << ans << "\n";
}
