#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
vll G[100100];
ll ng;
bool reachable[100100];
void dfs(ll v, ll p) {
  reachable[v] = true;
  for (auto nv : G[v]) {
    if (nv == ng) continue;
    if (nv == p) continue;
    dfs(nv, v);
  }
}
ll dist[100100];
void dfs2(ll v, ll p, ll c) {
  dist[v] = c;
  for (auto nv : G[v]) {
    if (nv == p) continue;
    dfs2(nv, v, c + 1);
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  for (long long i = (long long)(0); i < (long long)(n - 1); ++i) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<ll> q;
  q.emplace(u);
  q.emplace(v);
  vb visited(n);
  visited[u] = visited[v] = true;
  while (!q.empty()) {
    ll v = q.front();
    q.pop();
    bool flg = false;
    for (auto nv : G[v]) {
      if (visited[nv]) {
        ng = nv;
        flg = true;
        break;
      } else {
        visited[nv] = true;
        q.emplace(nv);
      }
    }
    if (flg) break;
  }
  dfs(u, -1);
  dfs2(v, -1, 0);
  ll ans = 0;
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    if (reachable[i]) {
      chmax(ans, dist[i]);
    }
  }
  ans--;
  cout << ans << endl;
}
