#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
struct rbtree: tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>{};
#define IN freopen("in.txt", "r", stdin);
#define endl '\n'
#define mp make_pair
#define pb push_back
#define lowb lower_bound
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mem0(a) memset((a), 0, sizeof(a))
#define mem(a, b) memset((a), (b), sizeof(a))
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const int N = 1e5+10;

VI g[N];
int deep[N], MaxDeep[N];

int ans = 0;
bool F = false;
int n, u, v;

void dfs(int son, int f, int depth){
    deep[son] = depth;
    if(son == u)F=1;
    if(g[son].size() == 1){
        if(F){
            if(deep[u]-deep[son] < deep[son]-1){
                ans = max(ans, MaxDeep[son]-2);
            }
        }
        MaxDeep[son] = depth;
    }
    for(auto it : g[son]){
        if(it == f)continue;
        if(son == v)F=0;
        dfs(it, son, depth+1);
        if(son == v)F=0;
        MaxDeep[son] = max(MaxDeep[son], MaxDeep[it]);
    }

}

int main(){
    IOS;
    //IN;
    cin>>n>>u>>v;
    for(int i = 1; i <= n-1; i++){
        int x, y; cin>>x>>y; g[x].eb(y), g[y].eb(x);
    }
    dfs(v, 0, 1);
    cout<<ans;
    return 0;
}