#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
vector<int> conn[N];
int du[N], dv[N];
void dfsU(int a, int d) {
  du[a] = d, d++;
  for (int b : conn[a]) {
    if (du[b] != -1) continue;
    dfsU(b, d);
  }
}
void dfsV(int a, int d) {
  dv[a] = d, d++;
  for (int b : conn[a]) {
    if (dv[b] != -1) continue;
    dfsV(b, d);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    conn[a].emplace_back(b);
    conn[b].emplace_back(a);
  }
  memset(du, -1, sizeof du);
  memset(dv, -1, sizeof dv);
  dfsU(u, 0);
  dfsV(v, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (ans < dv[i] && dv[i] < du[i]) ans = max(ans, dv[i]);
  cout << ans - 1 << endl;
}
