#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
vector<int> gr[N];
int depth[2][N]; // depth[0] is for chaser. depth[1]  is for runaway.
void dfs(int node, int from, int val, int *v){
    v[node] = val;
    for(auto it: gr[node]){
        if(it != from) dfs(it, node, val + 1, v);
    }
    return ;
}
int main(){
    int n, x, y, u, v;
    scanf("%d %d %d", &n, &u, &v);
    for(int i = 1; i < n; i++){
        scanf("%d %d", &x, &y);
        gr[x].push_back(y);
        gr[y].push_back(x);
    }
    dfs(u, 0, 0, depth[0]);
    dfs(v, 0, 0, depth[1]);
    int ma = 0;
    for(int i = 1; i <= n; i++){
        if(depth[0][i] < depth[1][i] && depth[1][i] > ma) ma = depth[1][i];
    }
    printf("%d", ma - 1);

}
