#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
vector<ll> vec1;
vector<ll> vec2;
vector<vector<ll> > gragh;
ll n, u, v;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> u >> v;
  u--;
  v--;
  gragh.resize(n);
  for (int i = 0; i < (int)(n - 1); i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    gragh[a].push_back(b);
    gragh[b].push_back(a);
  }
  vec1.resize(n, -1);
  vec2.resize(n, -1);
  queue<ll> q;
  vec1[u] = 0;
  q.push(u);
  while (!q.empty()) {
    ll temp = q.front();
    q.pop();
    for (int i = 0; i < (int)(gragh[temp].size()); i++) {
      if (vec1[gragh[temp][i]] == -1) {
        vec1[gragh[temp][i]] = vec1[temp] + 1;
        q.push(gragh[temp][i]);
      }
    }
  }
  queue<ll> q1;
  vec2[v] = 0;
  q1.push(v);
  while (!q1.empty()) {
    ll temp = q1.front();
    q1.pop();
    for (int i = 0; i < (int)(gragh[temp].size()); i++) {
      if (vec2[gragh[temp][i]] == -1) {
        vec2[gragh[temp][i]] = vec2[temp] + 1;
        q1.push(gragh[temp][i]);
      }
    }
  }
  ll res = 1e18;
  for (int i = 0; i < (int)(n); i++) {
    if (vec2[i] <= vec1[i]) {
      chmin(res, vec1[i]);
    }
  }
  cout << res << endl;
}
