#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> adj[maxn];
int distA[maxn], distB[maxn], color[maxn];
int visited[maxn];
int a, b;
void dfs1(int u, int par) {
  distA[u] = distA[par] + 1;
  for (auto v : adj[u]) {
    if (v != par) dfs1(v, u);
  }
}
void dfs2(int u, int par) {
  distB[u] = distB[par] + 1;
  for (auto v : adj[u]) {
    if (v != par) dfs2(v, u);
  }
}
int main() {
  int n;
  cin >> n >> b >> a;
  for (int i = 1, x, y; i < n; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(a, 0);
  queue<int> q;
  q.push(b);
  q.push(a);
  memset(color, -1, sizeof color);
  color[b] = 1;
  color[a] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (visited[u]) continue;
    visited[u] = 1;
    for (auto v : adj[u]) {
      if (color[v] == -1) color[v] = color[u];
      q.push(v);
    }
  }
  dfs2(b, 0);
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    if (color[i]) mx = max(mx, distB[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (color[i] && distB[i] == mx) ans = max(ans, distA[i] - 2);
  }
  cout << ans << endl;
  return 0;
}
