#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, u, v;
vector<vector<ll>> graph(1e5);
vector<ll> tmp;
vector<bool> visited(1e5, false);
ll preans = 0;
vector<ll> dd(1e5);
ll dfs(ll now) {
  visited.at(now) = true;
  ll i, j;
  for (i = 0; i < graph.at(now).size(); ++i) {
    ll next = graph.at(now).at(i);
    if (next == u) {
      tmp.push_back(now);
      return now;
    }
    if (!visited.at(next)) {
      ll sta = dfs(next);
      if (sta != -1) {
        tmp.push_back(now);
        return now;
      }
    }
  }
  return -1;
}
void dfs2(ll now) {
  ll i, j;
  visited.at(now) = true;
  ll dis = dd.at(now);
  for (i = 0; i < graph.at(now).size(); ++i) {
    ll next = graph.at(now).at(i);
    if (!visited.at(next)) {
      dd.at(next) = dis + 1;
      preans = max(preans, dis + 1);
      dfs2(next);
    }
  }
}
int main() {
  ll i, j;
  cin >> n >> u >> v;
  --u;
  --v;
  for (i = 0; i < n - 1; ++i) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }
  dfs(v);
  ll nu, nv;
  ll ans;
  if (tmp.size() % 2) {
    ans = (tmp.size() - 1) / 2;
    if (tmp.size() == 1) {
      nu = u;
      nv = v;
    } else {
      nu = tmp.at((tmp.size() - 1) / 2 - 1);
      nv = tmp.at((tmp.size() - 1) / 2);
    }
  } else {
    ans = tmp.size() / 2 - 1;
    if (tmp.size() == 2) {
      nu = u;
      nv = tmp.at(0);
    } else {
      nu = tmp.at(tmp.size() / 2 - 2);
      nu = tmp.at(tmp.size() / 2 - 1);
    }
  }
  for (i = 0; i < n; ++i) {
    visited.at(i) = false;
  }
  visited.at(nv) = true;
  dd.at(nu) = 0;
  dfs2(nu);
  ans += preans;
  if (tmp.size() % 2 == 0) ans += 1;
  cout << ans << endl;
  return 0;
}
