#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int n, u, v;
vector<vector<int>> p, parentk;
vector<int> d, parent;
void dfs(int i, int dep, int from) {
  d[i] = dep;
  parent[i] = from;
  for (auto &j : p[i]) {
    if (j == from) continue;
    dfs(j, dep + 1, i);
  }
}
int lca(int i, int j) {
  if (d[i] < d[j]) swap(i, j);
  int k = 22;
  while (k >= 0 && d[i] > d[j]) {
    if (d[parentk[k][i]] >= d[j]) {
      i = parentk[k][i];
    }
    k--;
  }
  k = 22;
  if (i == j) return i;
  while (k >= 0 && i != j) {
    if (parentk[k][i] != parentk[k][j]) {
      i = parentk[k][i];
      j = parentk[k][j];
    }
    k--;
  }
  return parent[i];
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> u >> v;
  u--;
  v--;
  p.resize(n);
  d.resize(n);
  parent.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  dfs(u, 0, u);
  parentk.resize(23);
  for (int i = 0; i < n; i++) parentk[0].push_back(parent[i]);
  for (int k = 1; k < 23; k++) {
    for (int i = 0; i < n; i++) {
      parentk[k].push_back(parentk[k - 1][parentk[k - 1][i]]);
    }
  }
  ll ans = d[v] / 2;
  for (int i = 0; i < n; i++) {
    int q = lca(v, i);
    if (d[v] - d[q] + d[i] - d[q] < d[i]) {
      continue;
    }
    ll diff = d[v] - 2 * d[q];
    if (q != i && diff == 0) {
      continue;
    }
    ans = max(ans, diff / 2 + d[i]);
  }
  cout << ans << endl;
  return 0;
}
