#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const ll INF = 1LL << 50;
int main() {
  cout << fixed << setprecision(15);
  ll n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  vvll to(n);
  for (ll i = 0; i < (n - 1); ++i) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
  }
  vll du(n, -1), dv(n, -1);
  queue<ll> que;
  que.push(u), du[u] = 0;
  while (!que.empty()) {
    ll x = que.front();
    que.pop();
    for (ll y : to[x]) {
      if (du[y] == -1) {
        du[y] = du[x] + 1;
        que.push(y);
      }
    }
  }
  que.push(v), dv[v] = 0;
  while (!que.empty()) {
    ll x = que.front();
    que.pop();
    for (ll y : to[x]) {
      if (dv[y] == -1) {
        dv[y] = dv[x] + 1;
        que.push(y);
      }
    }
  }
  ll tmx = 0;
  ll tchbn = 0;
  for (ll i = 0; i < (n); ++i) {
    if (tmx <= dv[i] - du[i]) {
      tchbn = max(tchbn, dv[i] - 1);
      tmx = du[i] - dv[i];
    }
  }
  cout << tchbn << endl;
  return 0;
}
