#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long pw(long long a, long long b) {
  if (b == 1) return (a + md) % md;
  if (b % 2 == 0)
    return (pw(a * a, b / 2) + md) % md;
  else
    return (a * pw(a * a, b / 2) + md) % md;
}
const int xn = 1e5 + 10;
const int xm = 5e4 + 10;
int n, a, b, dist[2][xn];
vector<int> adj[xn];
bool mark[xn];
void DFS(int v, int dx) {
  mark[v] = true;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (mark[u]) continue;
    dist[dx][u] = dist[dx][v] + 1;
    DFS(u, dx);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> a >> b;
  int v, u;
  for (int i = 0; i < n - 1; i++)
    cin >> v >> u, adj[v].push_back(u), adj[u].push_back(v);
  DFS(a, 0);
  for (int i = 0; i <= n; i++) mark[i] = false;
  DFS(b, 1);
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    if (dist[1][i] > dist[0][i]) mx = max(mx, dist[0][i]);
  }
  cout << mx << '\n';
  return 0;
}
