#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
int step1[100005], step2[100005];
int vis1[100005], vis2[100005];
int n, s1, s2, u, v;
void bfs(int k) {
  memset(vis1, 0, sizeof(vis1));
  memset(vis2, 0, sizeof(vis2));
  memset(step1, 0, sizeof(step1));
  memset(step2, 0, sizeof(step2));
  if (k == s1) {
    queue<int> q;
    q.push(k);
    step1[k] = 0;
    vis1[k] = 1;
    while (!q.empty()) {
      int a = q.front();
      q.pop();
      for (int b : G[a]) {
        if (!vis1[b]) {
          step1[b] = step1[a] + 1;
          vis1[b] = 1;
          q.push(b);
        }
      }
    }
  } else if (k == s2) {
    queue<int> q;
    q.push(k);
    step2[k] = 0;
    vis2[k] = 1;
    while (!q.empty()) {
      int a = q.front();
      q.pop();
      for (int b : G[a]) {
        if (!vis2[b]) {
          step2[b] = step2[a] + 1;
          vis2[b] = 1;
          q.push(b);
        }
      }
    }
  }
}
int main() {
  cin >> n >> s1 >> s2;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bfs(s1);
  bfs(s2);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (step1[i] < step2[i]) ans = max(ans, step2[i]);
  }
  cout << ans - 1;
  return 0;
}
