#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, t, a;
  cin >> n >> t >> a;
  t--;
  a--;
  vector<vector<int>> G(n);
  for (int i = 0; i < (n - 1); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<int> td(n, -1), ad(n, -1);
  queue<int> q;
  q.push(t);
  td[t] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (const auto& nv : G[v]) {
      if (td[nv] != -1) continue;
      if (nv == a) continue;
      td[nv] = td[v] + 1;
      q.push(nv);
    }
  }
  q.push(a);
  ad[a] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (const auto& nv : G[v]) {
      if (ad[nv] != -1) continue;
      ad[nv] = ad[v] + 1;
      q.push(nv);
    }
  };
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    if (td[i] != -1) chmax(ans, ad[i]);
  }
  cout << ans - 1 << endl;
}
