#include <bits/stdc++.h>
std::vector<int> g[100005];
int disA[100005], disT[100005];
int vis[100005];
int Q[100005];
int max(int a, int b) { return a > b ? a : b; }
int solve(int n, int A, int T) {
  if (A == T) return 0;
  if (g[T].size() == 1 && g[T][0] == A) return 0;
  for (int i = 1; i <= n; i++) vis[i] = 0;
  vis[A] = 1;
  int h = 0, t = -1;
  Q[++t] = A;
  while (h <= t) {
    int u = Q[h++];
    for (unsigned int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (vis[v]) continue;
      disA[v] = disA[u] + 1;
      vis[v] = 1;
      Q[++t] = v;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) vis[i] = 0;
  vis[T] = 1;
  h = 0, t = -1;
  Q[++t] = T;
  while (h <= t) {
    int u = Q[h++];
    for (unsigned int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (vis[v]) continue;
      vis[v] = 1;
      disT[v] = disT[u] + 1;
      if (disT[v] <= disA[v]) {
        if (disT[v] != disA[v]) Q[++t] = v;
        if ((disT[A]) % 2 == 0 && disT[v] != disA[v])
          ans = max(ans, disA[v] - 1);
        else
          ans = max(ans, disA[v]);
      }
    }
  }
  return ans;
}
int main() {
  int n, t, a;
  scanf("%d%d%d", &n, &t, &a);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  printf("%d\n", solve(n, a, t));
  return 0;
}
