#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
const int MAX_V = 1e5;
vector<int> g[MAX_V], du(MAX_V,-1), dv(MAX_V,-1);

void dfs(int p, int l, int f) {
  f == 0 ? du[p] = l : dv[p] = l;  
  for(auto k : g[p]) {
    if((f == 0 && du[k] == -1) || (f == 1 && dv[k] == -1)) dfs(k,l+1,f);
  }
}

int main(){
  int n, u, v, x, y;
  cin >> n >> u >> v;
  u--; v--;
  rep(i,n-1) {
    cin >> x >> y;
    x--; y--;
    g[x].push_back(y); g[y].push_back(x);
  }
  if(g[u].size() == 1 && g[u][0] == v) {
    cout << 0 << endl;
    return 0;
  }
  dfs(u,0,0); dfs(v,0,1);
  int ans = 1;
  rep(i,n) {
    if(du[i] < dv[i]) ans = max(ans,dv[i]-1);
  }
  cout << ans << endl;
  return 0;
}