/**
 *    created by : PawPaw       
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  

using namespace __gnu_pbds;  
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,  
        tree_order_statistics_node_update>  
        ordered_set;  

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define PHI acos(-1)
#define EPS 0.000000001
#define N 100002
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define FbO find_by_order
#define OoK order_of_key

int visa[N];
bool vis[N];
vector<int> adj[N];

void dfsa(int u, int time){
  visa[u] = time;
  for(int v : adj[u]){
    if(visa[v] == -1)
      dfsa(v, time+1);
  }
}

int dfst(int u, int time){
  if(time >= visa[u]) return visa[u];
  bool leaf = true;
  int ret = 0;
  vis[u] = true;
  for(int v : adj[u]){
    if(!vis[v]){
      leaf = false;
      ret = max(ret, dfst(v, time+1));
    }
  }
  if(leaf) ret = visa[u]-1;
  return ret;
}

int solve(){
  int n, u, v, a, b;
  fill(visa, visa+N, -1);
  fill(vis, vis+N, false);

  cin >> n >> u >> v;
  F(i, 1, n-1){
    cin >> a >> b;
    adj[a].PB(b);
    adj[b].PB(a);
  }

  dfsa(v, 0);
  cout << dfst(u, 0) << '\n';

  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

int main(){
  ios::sync_with_stdio(false); 
  cin.tie(0);
  fun();
  return 0;
}