#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;
void dfs(const Graph &G, int v, int p, vector<long long> &Astep) {
  for (auto nv : G[v]) {
    if (nv == p) {
      continue;
    } else {
      Astep[nv] = Astep[v] + 1;
      dfs(G, nv, v, Astep);
    }
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  Graph G(N);
  for (long long i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  vector<long long> Astep(N, -1);
  vector<long long> Tstep(N, -1);
  Astep[u - 1] = 0;
  Tstep[v - 1] = 0;
  dfs(G, u - 1, -1, Astep);
  dfs(G, v - 1, -1, Tstep);
  long long ans = -1;
  for (long long i = 0; i < N; i++) {
    if (Astep[i] > Tstep[i]) {
      if (ans < Tstep[i]) ans = Astep[i];
    }
  }
  cout << ans << endl;
  return 0;
}
