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

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,s,t;
    cin>>n>>s>>t;
    s--,t--;
    Dijkstra dij(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        dij.add_undirected_edge(a,b,1);
    }
    int now = 0;
    int p = 0;
    vector<ll> d=dij.shortest_path(0);
    for(int i=0;i<n;i++){
        if(now < d[i]){
            now = d[i];
            p=i;
        }
    }
    vector<ll> f=dij.shortest_path(p);
    now=0;
    int q=0;
    for(int i=0;i<n;i++){
        if(now<f[i]){
            now = f[i];
            q=i;
        }
    }
    bool used[n]={};
    for(int i=0;i<n;i++){
        if(now == d[i] + f[i]) used[i]=1;
    }
    vector<ll> sd = dij.shortest_path(s);
    vector<ll> td = dij.shortest_path(t);
    ll ans = -1;
    if(sd[p]==td[p]) ans = max(ans,sd[t]/2);
    if(sd[q]==td[p]) ans = max(ans,sd[t]/2);
    for(int i=0;i<n;i++){
        if(i==s || i==t) continue;
        if(sd[i] < td[i]){
            ans = max(ans, td[p]-1);
        }
    }
    cout << ans << endl;


}
