#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int N;
  cin >> N;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  vector<vector<int>> t(N);
  int a, b;
  int ans = 0;
  for (int i = 0; i < (N - 1); i++) {
    cin >> a >> b;
    a--;
    b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  vector<int> dfu(N, -1);
  vector<int> dfv(N, -1);
  queue<int> qu, qv;
  qu.push(u);
  dfu[u] = 0;
  while (!qu.empty()) {
    int now = qu.front();
    qu.pop();
    for (int i = 0; i < ((int)t[now].size()); i++) {
      if (dfu[t[now][i]] >= 0) continue;
      qu.push(t[now][i]);
      dfu[t[now][i]] = dfu[now] + 1;
    }
  }
  qv.push(v);
  dfv[v] = 0;
  while (!qv.empty()) {
    int now = qv.front();
    qv.pop();
    for (int i = 0; i < ((int)t[now].size()); i++) {
      if (dfv[t[now][i]] >= 0) continue;
      qv.push(t[now][i]);
      dfv[t[now][i]] = dfv[now] + 1;
    }
  }
  vector<int> duv(N, -1);
  for (int i = 0; i < (N); i++) {
    duv[i] = dfv[i] - dfu[i];
  }
  vector<int> d(N);
  queue<int> q;
  q.push(u);
  d[u] = duv[u];
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < ((int)t[now].size()); i++) {
      if (d[t[now][i]] >= 0) continue;
      q.push(t[now][i]);
      d[t[now][i]] = min(d[now], duv[t[now][i]]);
    }
  }
  int maxd = 0;
  for (int i = 0; i < (N); i++) {
    maxd = max(maxd, d[i]);
  }
  cout << maxd << endl;
  return 0;
}
