#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);
    }
  }
  int ans = 0;
  vector<int> stepFromU(n, -1);
  stepFromU[u] = 0;
  qu.push(u);
  while (!qu.empty()) {
    int now = qu.front();
    qu.pop();
    if (graph[now].size() == 1) {
      ans = max(ans, stepFromV[now] - 1);
    }
    for (int i = 0; i < graph[now].size(); i++) {
      int next = graph[now][i];
      if (next == v || stepFromU[next] >= 0 ||
          stepFromV[next] == stepFromU[now] + 1)
        continue;
      stepFromU[next] = stepFromU[now] + 1;
      qu.push(next);
    }
  }
  cout << ans << endl;
}
