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

int main() {
  int n;
  vi u(2);
  cin >> n >> u[0] >> u[1];
  u[0]--;
  u[1]--;
  vector<vi> g(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<vi> d(2, vi(n, -1));
  rep(k, 2) {
    queue<int> q;
    q.push(u[k]);
    d[k][u[k]] = 0;
    while(!q.empty()) {
      int i = q.front();
      q.pop();
      for(auto ni : g[i]) {
        if(d[k][ni] != -1) continue;
        d[k][ni] = d[k][i] + 1;
        q.push(ni);
      }
    }
  }
  int mx = 0;
  rep(i, n) if(d[0][i] < d[1][i]) mx = max(mx, d[1][i]);
  cout << mx - 1 << endl;
}