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

int main() {
  int V,B,A;
  cin>>V>>B>>A;
  B--,A--;
  vector<vector<int>> G(V);
  for(int i=0;i<V-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<int> q;
  q.push(A);
  vector<int> oya(V,-1);
  vector<int> huka(V);
  oya[A]=-2;
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:G[a]){
      if(oya[x]==-1){
        oya[x]=a;
        q.push(x);
        huka[x]=1+huka[a];
      }
    }
  }
  int Z=0;
  Z+=huka[B]/2;
  int L=(huka[B]-1)/2;
  for(int i=0;i<L;i++){
    B=oya[B];
  }
  int X=huka[B];
  q.push(B);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:G[a]){
      if(huka[x]>huka[a]){
        q.push(x);
        X=huka[x];
      }
    }
  }
  Z+=X;
  Z-=huka[B];
  cout<<Z<<endl;
}