#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> find_path(vector<vector<ll>> &g, ll from, ll to, ll parent = -1) {
  if (from == to) return vector<ll>{to};
  for (ll next : g[from]) {
    if (next == parent) continue;
    vector<ll> found = find_path(g, next, to, from);
    if (!found.empty()) {
      found.push_back(from);
      return found;
    }
  }
  return {};
}
vector<ll> find_longest(vector<vector<ll>> &g, ll from, ll parent = -1) {
  ll cnt = 0;
  vector<ll> found = {from};
  for (ll next : g[from]) {
    if (next == parent) continue;
    found = find_longest(g, next, from);
    found.push_back(from);
    if (cnt < (ll)found.size()) cnt = found.size() + 1;
  }
  return found;
}
int main() {
  ll n, u, v;
  cin >> n >> u >> v;
  vector<vector<ll>> g(n + 1);
  ll a, b;
  for (ll i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ll up;
  vector<ll> path = find_path(g, u, v);
  if (path.size() >= 4) {
    up = (path.size() - 2) / 2;
  } else {
    up = 0;
  }
  u = path[path.size() - 1 - up];
  v = path[up + path.size() % 2];
  if (path.size() % 2 == 1) {
    up++;
  }
  vector<ll> longest = find_longest(g, u, v);
  ll down = longest.size() - 1;
  cout << up + down << endl;
}
