#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, q;
  cin >> n >> p >> q;
  p--;
  q--;
  vector<int> v[n];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int ds, prev[n];
  {
    int dis = 1;
    bool done = false;
    queue<pair<int, int> > que[2];
    que[1].push({p, -1});
    while (true) {
      int dd = dis % 2, de = (dis % 2 + 1) % 2;
      pair<int, int> nw = que[dd].front();
      que[dd].pop();
      for (int x : v[nw.first]) {
        if (x == nw.second)
          continue;
        else if (x == q) {
          done = true;
          break;
        } else
          que[de].push({x, p});
      }
      if (done) break;
      dis++;
    }
    ds = dis;
  }
  int tm[n], tm2[n];
  fill(tm, tm + n, 1e9);
  fill(tm2, tm2 + n, -1);
  tm[p] = 0;
  tm2[q] = 0;
  {
    int done = 1, dis = 1;
    queue<int> que[2];
    que[dis % 2].push(q);
    while (done < n) {
      int dd = dis % 2, de = (dis % 2 + 1) % 2;
      int nw = que[dd].front();
      que[dd].pop();
      for (int x : v[nw]) {
        if (tm2[x] != -1)
          continue;
        else {
          que[de].push(x);
          tm2[x] = dis;
          done++;
        }
      }
      dis++;
    }
  }
  int mx = 0;
  {
    int done = 1, dis = 1;
    queue<int> que[2];
    que[1].push(p);
    while (true) {
      int dd = dis % 2, de = (dis % 2 + 1) % 2;
      if (que[dd].empty()) break;
      int nw = que[dd].front();
      que[dd].pop();
      for (int x : v[nw]) {
        if (tm[x] != 1e9)
          continue;
        else if (tm2[x] >= dis)
          continue;
        else {
          que[de].push(x);
          tm[x] = dis;
        }
      }
      dis++;
    }
  }
  for (int i = 0; i < n; i++) {
    mx = max(mx, (tm2[i] - tm[i]) / 2);
  }
  cout << mx << endl;
}
