#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

// 木上の探索

void dfs(const Graph &G, vector<int> &td,int v, int p, int d) {
  td[v]=d;
  for (auto nv : G[v]) {
    if (nv == p) continue;
    dfs(G,td,nv,v,d+1);
  }
}

int main(){
  int n,u,v;
  cin >>n>>u>>v;
  --u;
  --v;
  Graph g(n);

  vector<int> td(n,0),ad(n,0);

  for(int i=0;i<n-1;++i) {
    int a,b;
    cin>>a>>b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1);
  }
  dfs(g,td,u,-1,0);
  dfs(g,ad,v,-1,0);
  int k=0;
  for(int i=0;i<n;++i){
    //      cout<<i<<" "<<ad[i]<<"\n";
    if(td[i]<ad[i]){
      //	cout<<td[i]<<" "<<ad[i]<<" "<<i<<"\n";
      k=max(k,ad[i]);
    }
  }
  cout<<k-1;
}
