#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
template <typename T>
void chmin(T &a, const T &b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, const T &b) {
  a = max(a, b);
}
struct FastIO {
  FastIO() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} fastiofastio;
const ll INF = 1LL << 60;
int main(void) {
  ll n, s, t;
  cin >> n >> s >> t;
  s--, t--;
  vector<vector<ll>> g(n);
  for (ll i = (ll)0; i < (ll)n - 1; ++i) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ll type;
  vector<vector<ll>> dist(2, vector<ll>(n));
  function<void(ll, ll, ll)> dfs = [&](ll v, ll p, ll d) {
    dist[type][v] = d;
    for (auto to : g[v]) {
      if (to == p) continue;
      dfs(to, v, d + 1);
    }
  };
  type = 0;
  dfs(s, -1, 0);
  type = 1;
  dfs(t, -1, 0);
  ll ret = 0;
  for (ll i = (ll)0; i < (ll)n; ++i) {
    if (dist[0][i] < dist[1][s]) {
      if (dist[0][i] < dist[1][i]) {
        chmax(ret, dist[1][i] - 1);
      }
    } else {
      chmax(ret, dist[1][i] - 1);
    }
  }
  cout << ret << endl;
  return 0;
}
