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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



struct Graph{
    struct Edge{
        int from;
        int to;
        ll  cost;

        Edge(int a, int b, ll c) : from(a), to(b), cost(c) {}
    };
    int N;
    vector<vector<Edge>> edges;
    vector<int> deg;
    vector<ll> dist;

    Graph(int n) : N(n), edges(n), deg(n, 0), dist(n, INF) {}

    bool visited(int v){
        return dist[v] < INF;
    }

    void resetDist(){
        for(int i=0; i<N; i++) dist[i] = INF;
    }

    void connect(int a, int b, ll c){
        edges[a].emplace_back(Edge(a, b, c));
        deg[b]++;
    }

    void dfs(int p, int v, ll d){
        if(visited(v)) return;
        dist[v] = d;
        for(auto e : edges[v]){
            if(e.to == p) continue;
            dfs(v, e.to, d + e.cost);
        }
    }

    bool isAcyclic(){
        static vector<int> status(N, 0);
        for(int i=0; i<N; i++){
            if(!isAcyclicDfs(status, i)) return false;
        }
        return true;
    }

    bool isAcyclicDfs(vector<int>& status, int v){
        status[v] = 1;
        for(auto e : edges[v]){
            if(status[e.to] == 1){
                return false;
            }else if(status[e.to] == 0){
                if(!isAcyclicDfs(status, e.to)){
                    return false;
                }
            }
        }
        status[v] = 2;
        return true;
    }

    int criticalLength(){
        vector<int> source;
        for(int i=0; i<N; i++){
            if(deg[i] == 0) source.push_back(i);
        }

        int cnt = 1;

        while(true){
            vector<int> v;
            for(int s : source){
                for(auto e : edges[s]){
                    deg[e.to]--;
                    if(deg[e.to] == 0){
                        v.push_back(e.to);
                    }
                }
            }
            if(v.empty()) break;
            source = v;
            cnt++;
        }
        return cnt;
    }
};

signed main(){
    int n, tk, ao;
    cin >> n >> tk >> ao;
    tk--;
    ao--;

    Graph G(n);
    REP(i, n-1){
        int a, b;
        cin >> a >> b;
        G.connect(a-1, b-1, 1);
        G.connect(b-1, a-1, 1);
    }

    G.dfs(-1, tk, 0);
    auto dist_tk = G.dist;

    G.resetDist();
    G.dfs(-1, ao, 0);
    auto dist_ao = G.dist;

    ll ans = 0;

    REP(i, n){
        if(dist_tk[i] > dist_ao[i]) continue;
        chmax(ans, dist_ao[i] - 1LL);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13440