#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int> > graph(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  vector<int> stepFromV(n, -1);
  queue<int> qu;
  qu.push(v);
  stepFromV[v] = 0;
  while (!qu.empty()) {
    int now = qu.front();
    qu.pop();
    for (int i = 0; i < graph[now].size(); i++) {
      int next = graph[now][i];
      if (stepFromV[next] >= 0) continue;
      stepFromV[next] = stepFromV[now] + 1;
      qu.push(next);
    }
  }
  queue<pair<int, int> > qu2;
  qu2.push(make_pair(u, 0));
  int ans = 0;
  while (!qu2.empty()) {
    int now = (qu2.front()).first;
    int step = (qu2.front()).second;
    qu2.pop();
    if (step > n) continue;
    for (int i = 0; i < graph[now].size(); i++) {
      int next = graph[now][i];
      if (step + 1 == stepFromV[next] || step == stepFromV[next]) {
        ans = max(ans, stepFromV[next]);
        continue;
      }
      qu2.push(make_pair(next, step + 1));
    }
  }
  cout << ans << endl;
}
