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

int n;
vector<int> G[108000];
int dist[108000], U, V;
bool cor[108000];

void dfs(int v, int p, int d)
{
    dist[v] = d;
    for(int &u : G[v])
        if(u != p)
            dfs(u, v, d + 1);
}

void solve(int v, int p, int d)
{
    cor[v] = true;
    for(int &u : G[v])
        if(u != p and dist[u] > d)
            solve(u, v, d + 1);
}

int32_t main()
{
    cin >> n >> U >> V;
    for(int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }    
    dfs(V, -1, 0);
    solve(U, -1, 0);
    int ans = 0;
    for(int i = 1; i <= n; i++)
        if(cor[i])
            ans = max(ans, dist[i] - 1);
    cout << ans << '\n';
    
    return 0;
}