#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> graph;
vector<long long> U;
vector<long long> V;
void dfsU(vector<vector<long long>> G, long long v, long long t) {
  U[v] = t, t++;
  for (auto next : G[v]) {
    if (U[next] != -1) continue;
    dfsU(G, next, t);
  }
}
void dfsV(vector<vector<long long>> G, long long v, long long t) {
  V[v] = t, t++;
  for (auto next : G[v]) {
    if (V[next] != -1) continue;
    dfsV(G, next, t);
  }
}
int main() {
  long long N, u, v;
  cin >> N >> u >> v;
  u--, v--;
  graph.resize(N);
  U.resize(N, -1);
  V.resize(N, -1);
  if (N < 2) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }
  dfsU(graph, u, 0);
  dfsV(graph, v, 0);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (ans < V[i] && U[i] < V[i]) {
      ans = V[i];
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
