#include <bits/stdc++.h>
using namespace std;
vector<int> e[100010];
int x[100010];
int d[100010];
int y[100010];
void search(int curr, int prev, int ter) {
  x[curr] = x[prev] + 1;
  if (curr == ter) return;
  for (auto &to : e[curr]) {
    if (to != prev) {
      search(to, curr, ter);
    }
  }
}
void search2(int curr, int prev, int u) {
  if (prev != 0) {
    if (x[curr] && x[prev] > x[curr]) {
      d[curr] = d[prev] - 2;
    } else
      d[curr] = d[prev];
    y[curr] = y[prev] + 1;
  }
  if (d[curr] <= 0) return;
  for (auto &to : e[curr]) {
    if (to != prev) {
      search2(to, curr, u);
    }
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    e[a].emplace_back(b);
    e[b].emplace_back(a);
  }
  x[0] = -1;
  y[0] = -1;
  search(v, 0, u);
  d[u] = x[u];
  search2(u, 0, u);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, y[i] + d[i] - 1);
  }
  cout << ans << "\n";
  return 0;
}
