#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
std::random_device rd;
std::mt19937 mt(rd());
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 2000020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr long long INF = 1e18;
vector<long long> G[200020];
long long ds[200020], dt[200020];
void dfs(long long n, long long pre, long long res, long long* d) {
  d[n] = res;
  for (auto nxt : G[n]) {
    if (nxt == pre) continue;
    dfs(nxt, n, res + 1, d);
  }
}
void solve() {
  long long N, s, t;
  cin >> N >> s >> t;
  s--, t--;
  for (long long i = 0; i < N - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(s, s, 0, ds);
  dfs(t, t, 0, dt);
  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    if (ds[i] < dt[i])
      ans = max(ans, ds[i]);
    else if (ds[i] == dt[i] && ds[i] + dt[i] == dt[s])
      ans = max(ans, ds[i]);
  }
  cout << (ans) << '\n';
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
