#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<vector<int>> G;
vector<int> A;
vector<int> B;
void dfs(int t, vector<int> &V, int cnt) {
  V[t] = cnt;
  for (auto e : G[t]) {
    if (V[e] != -1) continue;
    dfs(e, V, cnt + 1);
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  --u;
  --v;
  G.resize(N);
  A.resize(N, -1);
  B.resize(N, -1);
  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);
  }
  dfs(u, A, 0);
  dfs(v, B, 0);
  vector<pair<int, int>> P(N);
  for (int i = 0; i < (N); i++) P[i] = {A[i], B[i]};
  sort((P).begin(), (P).end());
  int before = -1;
  int ans = 0;
  for (int i = 0; i < (N); i++) {
    if (P[i].first < P[i].second) {
      if (ans + 2 == P[i].first) break;
      ans = max(ans, P[i].first);
    }
    if (P[i].first == P[i].second) {
      if (ans + 2 == P[i].first) break;
      ans = max(ans, P[i].first);
      break;
    }
  }
  cout << ans << endl;
}
