#include <bits/stdc++.h>
using namespace std;
long long n, t, a;
int v[100005], h[100005], ans, x, y;
vector<int> c[100005];
queue<int> q;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d %d %d", &n, &t, &a);
  v[t] = 1;
  h[a] = 1;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    c[x].push_back(y);
    c[y].push_back(x);
  }
  q.push(a);
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (int i = 0; i < c[x].size(); i++) {
      if (!v[c[x][i]]) {
        v[c[x][i]] = v[x] + 1;
        q.push(c[x][i]);
      }
    }
  }
  q.push(t);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < c[x].size(); i++) {
      if (v[c[x][i]] > h[x]) {
        if (h[c[x][i]] < h[x] + 1) {
          h[c[x][i]] = h[x] + 1;
          q.push(c[x][i]);
        }
      } else
        ans = max(ans, v[c[x][i]]);
    }
  }
  printf("%d", ans);
  return 0;
}
