#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--, v--;
  Graph G(N, vector<int>(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);
  }
  queue<int> que;
  vector<int> dist1(N, -1);
  que.push(u);
  dist1[u] = 0;
  while (!que.empty()) {
    int k = que.front();
    que.pop();
    for (auto nk : G[k]) {
      if (dist1[nk] != -1) continue;
      dist1[nk] = dist1[k] + 1;
      que.push(nk);
    }
  }
  vector<int> dist2(N, -1);
  que.push(v);
  dist2[v] = 0;
  int mdist = 0, lv, dif = 0;
  while (!que.empty()) {
    int k = que.front();
    que.pop();
    for (auto nk : G[k]) {
      if (dist2[nk] != -1) continue;
      dist2[nk] = dist2[k] + 1;
      que.push(nk);
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i)
    if (dist1[i] < dist2[i]) ans = max(dist2[i] - 1, ans);
  cout << ans << endl;
  return 0;
}
