#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long x, y, z;
  cin >> x >> y >> z;
  if (y == z)
    cout << 0;
  else {
    vector<long long> v[x + 1];
    for (int i = 0; i < x - 1; i++) {
      long long a, b;
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    long long k = 0;
    queue<long long> q;
    vector<long long> m(x + 1, 0);
    m[z] = 1;
    queue<long long> val;
    q.push(z);
    val.push(0);
    while (!q.empty()) {
      long long a = q.front();
      long long b = val.front();
      k = max(b, k);
      q.pop();
      val.pop();
      for (long long i : v[a]) {
        if (!m[i]) {
          q.push(i);
          val.push(b + 1);
          m[i] = 1;
        }
      }
    }
    cout << k - 1;
  }
  return 0;
}
