#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;
vector<int>G[MAXN];
int step1[MAXN], step2[MAXN];
bool vis1[MAXN], vis2[MAXN];
int n, s1, s2, u, v;
void bfs(int k) {
    if (k == s1) {
        queue<int>q;
        q.push(k);
        step1[k] = 0;
        vis1[k] = true;
        while (!q.empty()) {
            int a = q.front();
            q.pop();
            for (int b : G[a]) {
                if (!vis1[b]) {
                    step1[b] = step1[a] + 1;
                    vis1[b] = true;
                    q.push(b);
                }
            }
        }
    }
    else if (k == s2) {
        queue<int>q;
        q.push(k);
        step2[k] = 0;
        vis2[k] = true;
        while (!q.empty()) {
            int a = q.front();
            q.pop();
            for (int b : G[a]) {
                if (!vis2[b]) {
                    step2[b] = step2[a] + 1;
                    vis2[b] = true;
                    q.push(b);
                }
            }
        }
    }
}
int main() {
    memset(vis1, false, sizeof(vis1));
    memset(vis2, false, sizeof(vis2));
    memset(step1, 0, sizeof(step1));
    memset(step2, 0, sizeof(step2));
    cin >> n >> s1 >> s2;
    for (int i = 0; i < n - 1; i++) {
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    bfs(s1);
    bfs(s2);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (step1[i] < step2[i]) ans = max(ans, step2[i]);
    }
    cout << ans - 1;
    return 0;
}
