#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int T,A,n;
  cin >> n >> T >> A;
  T--,A--;
  vector<vector<int>> v(n);
  rep(i,n-1){
    int a,b;cin >> a >> b;
    a--,b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  ll res = 0;
  bool is = true;
  vector<int> next(n,T);
  {
    vector<int> dt(n,-1);
    dt[T] = 0;
    queue<int> que;
    que.push(T);
    while(!que.empty()){
      int ov = que.front();que.pop();
      for(int nv : v[ov]){
        if(dt[nv] != -1)continue;
        next[nv] = ov;
        dt[nv] = dt[ov] + 1;
        que.push(nv);
      }
    }
    if(dt[A] & 1){
      int d = dt[A];
      while(dt[next[A]] >= d-d/2)A = next[A];
      T = A;
      while(dt[next[T]] >= d/2 && next[T] != T)T = next[T];
      res += d/2;
    }else{
      int d = dt[A];
      while(dt[next[A]] >= d-(d-2)/2)A = next[A];
      T = A;
      while(dt[next[T]] >= (d-2)/2 && next[T] != T)T = next[T];
      res += (d-2)/2;
      is = false;
    }
  }
  int L = -1;
  {
    for(int ov : v[T])for(int nv : v[ov])if(nv == A){
      L = ov;
      break;
    }
  }
  queue<int> que;
  que.push(T);
  vector<int> d(n,-1);
  d[T] = 0;
  while(!que.empty()){
    int ov = que.front();que.pop();
    for(int nv : v[ov]){
      if(nv == A || d[nv] != -1 || nv == L)continue;
      d[nv] = d[ov]+1;
      que.push(nv);
    }
  }
  int K = T;
  rep(i,n)if(d[i] > d[K])K = i;
  if(is)res += d[K];
  else res += d[K]+1;
  cout << res << endl;

  /*////////////
  cout << "L :" << L << endl;
  printf("T :%d A :%d\n",T+1,A+1);

  */////////////


  return 0;
}
/*
7
4 7
1 2
1 3
2 4
2 5
3 6
3 7
*/
#include <cstdio>
#include <cmath>
using namespace std;
const int N=1e5+5;
const int E=N<<1;
const int mod=1e9+7;
int n,u,v;
int a[N],b[N];
int d1[N],d2[N];
int h[N],nx[E],to[E];
int ec;
int ans;
void ae(int u,int v)
{
	ec++;
	nx[ec]=h[u];
	to[ec]=v;
	h[u]=ec;
}
void dfs(int u,int f,int d[])
{
	d[u]=d[f]+1;
	for (int i=h[u];i;i=nx[i])
		if (to[i]!=f)
			dfs(to[i],u,d);
}
int main()
{
	scanf("%d%d%d",&n,&u,&v);
	for (int i=1;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		ae(a[i],b[i]);
		ae(b[i],a[i]);
	}
	dfs(u,0,d1);
	dfs(v,0,d2);
	for (int i=1;i<=n;i++)
		if (d1[i]<d2[i]&&d2[i]-2>ans)
			ans=d2[i]-2;
	printf("%d\n",ans);
	return 0;
}