#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vvp = vector<vector<pair<int, int>>>;
template <typename T>
using ve = vector<T>;
template <typename T>
using pq2 = priority_queue<T>;
template <typename T>
using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, u, v;
  cin >> N >> u >> v;
  u--, v--;
  vvi G(N);
  for (int i = 0; i < (N - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vi T(N, -1), A(N, -1);
  queue<int> tt, aa;
  tt.push(u);
  T[u] = 0;
  aa.push(v);
  A[u] = 0;
  while (!tt.empty()) {
    int a = tt.front();
    tt.pop();
    for (int p : G[a]) {
      if (T[p] >= 0) continue;
      T[p] = T[a] + 1;
      tt.push(p);
    }
  }
  while (!aa.empty()) {
    int a = aa.front();
    aa.pop();
    for (int p : G[a]) {
      if (A[p] >= 0) continue;
      A[p] = A[a] + 1;
      aa.push(p);
    }
  }
  int ans = 0;
  for (int i = 0; i < (N); i++)
    if (T[i] >= A[i]) chmax(ans, A[i]);
  cout << ans << endl;
  return 0;
}
