#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  int n, u, v;
  cin>>n>>u>>v;
  map<int,vector<int>> m;
  for(int i=0; i+1<n; i++) {
    int a, b;
    cin>>a>>b;
    if(m.find(a)==m.end()) {
      m[a] = vector<int>();
      m[a].push_back(b);
      m[b] = vector<int>();
      m[b].push_back(a);
    } else {
      m[a].push_back(b);
      m[b].push_back(a);
    }
  }
  queue<int> q;
  q.push(v);
  vector<int> vis(n,0);
  vector<int> level(n,0);
  vis[v-1] = 1;
  while(!q.empty()) {
    int now = q.front();
    q.pop();
    l++;
    for(auto next : m[now]) {
      if(vis[next-1]==1) continue;
      q.push(next);
      vis[next-1] = 1;
      level[next-1] = level[now-1]+1;
    }
  }
  vector<int> lev(n,0);
  l = 0;
  rep(i,n) vis[i] = 0;
  vis[u-1] = 1;
  q.push(u);
  while(!q.empty()) {
    int now = q.front();
    q.pop();
    for(auto next : m[now]) {
      if(vis[next-1]==1) continue;
      q.push(next);
      vis[next-1] = 1;
      lev[next-1] = lev[now-1]+1;
    }
  }
  int ans = 0;
  rep(i,n) {
    if(level[i] > lev[i])
      ans = max(ans, level[i]-1);
  }
  std::cout << ans << std::endl;
  // std::cout << level << std::endl;
  // std::cout << lev << std::endl;

  return 0;
}
