#include <bits/stdc++.h>
using namespace std;
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 1e5 + 23;
vector<int> g[N];
bool dame[N], bio[N];
void solve() {
  int n, t, a;
  scanf("%d%d%d", &n, &t, &a);
  --t;
  --a;
  for (int u, v, i = 0; i < n - 1; ++i) {
    scanf("%d%d", &u, &v);
    g[--u].push_back(--v);
    g[v].push_back(u);
  }
  queue<pair<int, int>> q[2];
  int ans[2] = {}, turn = 0;
  q[0].emplace(t, 0);
  q[1].emplace(a, 0);
  dame[a] = 1;
  bio[t] = 1;
  while (q[0].size() && q[1].size()) {
    const auto &p = q[turn].front();
    ;
    ;
    int d = p.second;
    ;
    ans[turn] = d;
    if (turn || !dame[p.first]) {
      for (int v : g[p.first]) {
        if (dame[v]) continue;
        if (!turn && bio[v]) continue;
        if (turn)
          dame[v] = 1;
        else
          bio[v] = 1;
        q[turn].emplace(v, p.second + 1);
      }
    }
    q[turn].pop();
    if (q[turn].front().second != d) turn = !turn;
  }
  while (q[1].size()) {
    ans[1] = q[1].front().second;
    q[1].pop();
  }
  printf("%d", ans[1]);
}
int main() {
  init();
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
