#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
vector<int> dist;
int res = 0;
void dfs(int nod, int prev = -1, int pasi = 0) {
  res = max(res, pasi);
  for (auto i : v[nod])
    if (i != prev) {
      int p = pasi + 1;
      if (dist[i] == pasi + 1) res = max(res, pasi + 1);
      if (dist[i] > pasi + 1) dfs(i, nod, pasi + 1);
    }
}
void solve() {
  int n, a, b;
  cin >> n >> a >> b;
  v.resize(n + 1);
  dist.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<int> q;
  dist[b] = 1;
  q.push(b);
  while (!q.empty()) {
    int nod = q.front();
    q.pop();
    for (auto i : v[nod])
      if (dist[i] == 0) {
        dist[i] = dist[nod] + 1;
        q.push(i);
      }
  }
  for (int i = 1; i <= n; i++) dist[i]--;
  dfs(a);
  cout << res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  while (t--) {
    solve();
  }
}
