#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
vector<int> graph[100007];
int dist[100007];
int d2[100007];
void dfs(int u, int p = -1) {
  if (p != -1) dist[u] = dist[p] + 1;
  for (auto& v : graph[u])
    if (v != p) dfs(v, u);
}
void dfs2(int v, int p = -1) {
  if (p == -1)
    d2[v] = 0;
  else
    d2[v] = d2[p] + 1;
  if (d2[v] == dist[v]) return;
  for (auto& i : graph[v])
    if (i != p) dfs2(i, v);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < (int)n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(u);
  memset(d2, -1, sizeof d2);
  dfs2(v);
  int ans = -1;
  for (int i = 0; i < (int)n; i++) {
    ans = max(ans, d2[i] - (d2[i] != dist[i]));
  }
  cout << ans << '\n';
  return 0;
}
