#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

void dfs(vector<vector<int>> &G, vector<int> &D, int v) {
    for (int next : G[v]) {
        if (D[next] != -1) continue;
        D[next] = D[v] + 1;
        dfs(G, D, next);
    }
}

int main() {
    int N, U, V; cin >> N >> U >> V;
    U--; V--;

    vector<vector<int>> G(N);
    REP(i, 0, N - 1) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> D_V(N, -1);
    D_V[V] = 0;
    dfs(G, D_V, V);
    
    vector<int> D_U(N, -1);
    D_U[U] = 0;
    dfs(G, D_U, U);

    int dist = 0;
    REP(i, 0, N) {
        if (dist < D_V[i] && D_V[i] > D_U[i]) dist = D_V[i];
    }
    cout << dist - 1 << endl;
    return 0;
}