#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long INF = 1e9;
const long long MOD = INF + 7;
void solve() {
  long long n, s, e;
  cin >> n >> s >> e;
  s--;
  --e;
  vector<long long> g[n];
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<long long> dx(n), dy(n);
  function<void(long long, long long, long long)> dfs =
      [&](long long cur, long long par, long long dis) {
        for (long long x : g[cur]) {
          if (x != par) dfs(x, cur, dis + 1);
        }
        dx[cur] = dis;
      };
  function<void(long long, long long, long long)> dfs2 =
      [&](long long cur, long long par, long long dis) {
        for (long long x : g[cur]) {
          if (x != par) dfs(x, cur, dis + 1);
        }
        dy[cur] = dis;
      };
  dfs(s, -1, 0);
  dfs2(e, -1, 0);
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    if (dx[i] >= dy[i]) res = max(res, dx[i]);
  }
  cout << max(0LL, --res) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
