#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  swap(u, v);
  vector<vector<int>> 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);
  }
  if (u == v) return cout << 0 << endl, 0;
  vector<int> d(n, -1), ok(n);
  queue<tuple<int, int, int>> q;
  q.push({0, 0, u});
  while (not q.empty()) {
    int dist, good, k;
    tie(dist, good, k) = q.front();
    q.pop();
    if (d[k] != -1) continue;
    if (k == v) good = 1;
    d[k] = dist;
    ok[k] = good;
    for (auto& l : g[k]) {
      q.push({dist + 1, good, l});
    }
  }
  vector<int> d1(n, -1);
  queue<pair<int, int>> qu;
  qu.push({0, v});
  while (not qu.empty()) {
    int dist, k;
    tie(dist, k) = qu.front();
    qu.pop();
    if (d1[k] != -1) continue;
    d1[k] = dist;
    for (auto& l : g[k]) qu.push({dist + 1, l});
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    if (d1[i] < d[i]) ans = max(ans, d[i] - 1);
  }
  cout << ans << endl;
}
