#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
}
template <class t, class u>
void chmin(t& a, u b) {
  if (b < a) a = b;
}
int main() {
  int n, u, r;
  cin >> n >> u >> r;
  u--;
  r--;
  Graph G(n);
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<int> q;
  vi taka(n, -1);
  taka[u] = 0;
  q.push(u);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto t : G[v]) {
      if (taka[t] != -1) continue;
      taka[t] = taka[v] + 1;
      q.push(t);
    }
  }
  q.push(r);
  vi aoki(n, -1);
  aoki[r] = 0;
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto t : G[v]) {
      if (aoki[t] != -1) continue;
      aoki[t] = aoki[v] + 1;
      q.push(t);
    }
  }
  int target = 0;
  int distance = 0;
  for (int i = 0; i < (int)(n); i++)
    if (taka[i] <= aoki[i] && distance < taka[i]) {
      distance = taka[i];
      target = i;
    }
  int ans = aoki[target] - 1;
  cout << max(ans, 0) << endl;
}
