#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10, INF = 0x3f3f3f3f;
const double EPS = 1e-10, PI = acos(-1.);
vector<int> G[M];
int n, s, t, d[2][M];
void dfs(int u, int dis, int ma, int fa) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    d[ma][v] = dis + 1;
    dfs(v, dis + 1, ma, u);
  }
}
int main() {
  scanf("%d%d%d", &n, &t, &s);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(s, 0, 0, -1), dfs(t, 0, 1, -1);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (G[i].size() == 1 && i != s && i != t) {
      int u = G[i][0];
      if (d[0][u] >= d[1][u]) ans = max(ans, d[0][u]);
    }
  printf("%d\n", ans);
  return 0;
}
