#include <bits/stdc++.h>
using namespace std;
int n, a, b, dt1[101010], ans = -1;
vector<int> v[101010];
int main() {
  cin >> n >> b >> a;
  for (int i = 0; i < n - 1; i++) {
    int aa, bb;
    cin >> aa >> bb;
    v[aa].push_back(bb);
    v[bb].push_back(aa);
  }
  memset(dt1, 0x3f, sizeof(dt1));
  queue<pair<int, int> > q;
  q.push(make_pair(a, 0));
  dt1[a] = 0;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 0; i < v[x].size(); i++) {
      int z = v[x][i];
      if (dt1[z] < y + 1) {
        continue;
      }
      dt1[z] = y + 1;
      q.push(make_pair(z, y + 1));
    }
  }
  q.push(make_pair(b, 0));
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 0; i < v[x].size(); i++) {
      int z = v[x][i];
      if (dt1[z] <= y) {
        ans = max(ans, dt1[z]);
      } else {
        q.push(make_pair(z, y + 1));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
