#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
// #define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }

const int sz = 2e5+1;

void dfs(int node,int curr,bool vis[],int dis[],map<int,vector<int>>& tree){
  if(vis[node]) return;
  else{
    vis[node] = true;
    dis[node] = curr;

    for(int i=0;i<tree[node].size();i++){
      if(!vis[tree[node][i]]){
        dfs(tree[node][i],curr+1,vis,dis,tree);
      }
    }
  }
}

int32_t main(){
    
  fast;
  int n,x,y; cin >> n >> x >> y;
  map<int,vector<int>> tree;

  for(int i=1;i<=n-1;i++){
    int a,b; cin >> a >> b;
    tree[a].pb(b);
    tree[b].pb(a);
  }

  bool vis1[sz] = {false},vis2[sz]={false};
  int dis1[sz]={0},dis2[sz]={0};
  
  dfs(x,0,vis1,dis1,tree);
  dfs(y,0,vis2,dis2,tree);

  int ans = -1;

  for(int i=1;i<=n;i++){
    if(dis1[i]<dis2[i]){
      ans = max(ans,dis2[i]-1);
    }
  }
  
  cout << ans << '\n';

  return 0;
}