#include <bits/stdc++.h>
using namespace std;
vector<long long> v[100005];
long long x, y, vis[100005], ans, z, gg;
int dfs(long long p, long long q) {
  if (p == y) return 1;
  long long k = 0;
  for (int i = 0; i < v[p].size(); i++) {
    if (v[p][i] != q) k += dfs(v[p][i], p);
  }
  if (k) {
    vis[p] = 1;
    return 1;
  } else
    return 0;
}
void dfs2(long long p, long long q, long long s) {
  if (s > ans) ans = s;
  for (int i = 0; i < v[p].size(); i++) {
    if (v[p][i] != q) dfs2(v[p][i], p, s + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q, r;
  cin >> n >> x >> y;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vis[y] = 1;
  vis[x] = 1;
  dfs(x, -1);
  for (i = 0; i < v[y].size(); i++) {
    if (vis[v[y][i]]) r = v[y][i];
  }
  dfs2(r, y, 1);
  cout << ans - 1 << '\n';
  return 0;
}
