#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, s, t;
  cin >> n >> s >> t;
  vector<vector<int>> G(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  function<void(int, int, vector<int>& dis, vector<int>& path)> dfs =
      [&](int u, int p, vector<int>& dis, vector<int>& path) -> void {
    dis[u] = dis[p] + 1;
    for (int v : G[u]) {
      if (v == p) continue;
      path[v] = u;
      dfs(v, u, dis, path);
    }
  };
  vector<int> path_s(n + 1), path_t(n + 1);
  vector<int> dis_s(n + 1), dis_t(n + 1);
  dis_s[0] = dis_t[0] = -1;
  dfs(s, 0, dis_s, path_s);
  dfs(t, 0, dis_t, path_t);
  int ans = 0;
  int eq = INT_MAX;
  for (int i = 1; i <= n; i++) {
    if (i == s or i == t) continue;
    if (dis_s[i] == dis_t[i]) eq = min(eq, dis_s[i]);
    if (dis_s[i] < dis_t[i]) ans = max(ans, dis_t[i] - 1);
  }
  if (eq < INT_MAX) ans = max(ans, eq);
  cout << ans << '\n';
  return (0);
}
