#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
vector<vector<int>> gr;
void dfs(int v, int p, int depth, vector<vector<int>>& levels) {
  levels[depth].push_back(v);
  for (int u : gr[v])
    if (u != p) dfs(u, v, depth + 1, levels);
}
vector<vector<int>> a, b;
bool check(int m) {
  set<int> x, y;
  for (int i = m; i >= 0; i -= 2) {
    for (int j : a[i]) x.insert(j);
    for (int j : b[i]) y.insert(j);
  }
  for (int i : x)
    if (y.find(i) == y.end()) return false;
  return true;
}
bool check1(int m) {
  set<int> x, y;
  for (int i = m; i >= 0; i -= 2) {
    for (int j : a[i]) x.insert(j);
    for (int j : b[i - 1]) y.insert(j);
  }
  for (int i : x)
    if (y.find(i) == y.end()) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y, x--, y--;
  gr.resize(n);
  for (int i = (int)1; i < (int)n; i++) {
    int v, u;
    cin >> v >> u, v--, u--;
    gr[v].push_back(u), gr[u].push_back(v);
  }
  a.resize(n), b.resize(n);
  dfs(x, -1, 0, a), dfs(y, -1, 0, b);
  int l = 0, r = n - 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m;
  }
  int ans;
  if (check(r))
    ans = r;
  else
    ans = 0;
  l = 1, r = n - 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check1(m))
      r = m;
    else
      l = m;
  }
  if (check1(r)) ans = max(ans, r - 1);
  cout << ans;
  return 0;
}
