#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long modpow(long long n, long long k) {
  if (k == 1) {
    return n;
  } else if (k == 0) {
    return 1;
  } else if (k % 2 == 0) {
    long long memo = modpow(n, k / 2) % 1000000007;
    return memo * memo % 1000000007;
  } else {
    return n * modpow(n, k - 1) % 1000000007;
  }
}
int main() {
  long long n;
  cin >> n;
  long long u, k;
  cin >> u >> k;
  u--;
  k--;
  vector<long long> v[n];
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  long long aoki[n];
  for (int i = 0; i < n; i++) {
    aoki[i] = -1;
  }
  aoki[k] = 0;
  queue<long long> q;
  q.push(k);
  while (!q.empty()) {
    long long l = q.front();
    long long now = aoki[l];
    q.pop();
    for (int i = 0; i < v[l].size(); i++) {
      if (aoki[v[l][i]] == -1) {
        aoki[v[l][i]] = now + 1;
        q.push(v[l][i]);
      }
    }
  }
  long long taka[n];
  for (int i = 0; i < n; i++) {
    taka[i] = -1;
  }
  taka[u] = 0;
  q.push(u);
  while (!q.empty()) {
    long long l = q.front();
    long long now = taka[l];
    q.pop();
    for (int i = 0; i < v[l].size(); i++) {
      long long next = v[l][i];
      if (taka[next] == -1 && aoki[next] >= now + 1) {
        taka[next] = now + 1;
        if (aoki[next] > now + 1) q.push(next);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    long long t = aoki[i] - taka[i];
    t--;
    taka[i] += t;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, taka[i]);
  }
  cout << ans << endl;
  return 0;
}
