#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
long long mod = 1000000007;
int N, u, v;
vector<vector<int>> edge(100010);
int distance_u[100010];
int distance_v[100010];
void dist_u(int u) {
  queue<int> q;
  q.push(u);
  bool reached[100010] = {};
  reached[u] = true;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    if (now == v) continue;
    for (auto nv : edge[now]) {
      if (reached[nv]) continue;
      distance_u[nv] = distance_u[now] + 1;
      reached[nv] = true;
      q.push(nv);
    }
  }
  return;
}
void dist_v(int v) {
  queue<int> q;
  q.push(v);
  bool reached[100010] = {};
  reached[v] = true;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (auto nv : edge[now]) {
      if (reached[nv]) continue;
      distance_v[nv] = distance_v[now] + 1;
      reached[nv] = true;
      q.push(nv);
    }
  }
  return;
}
int main() {
  cin >> N >> u >> v;
  u--;
  v--;
  distance_u[u] = 0;
  distance_v[v] = 0;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }
  if (edge[u].size() == 1 && edge[u][0] == v) {
    cout << "0" << endl;
    return 0;
  }
  vector<int> cand;
  for (int i = 0; i < N; i++) {
    if (edge[i].size() == 1) {
      cand.emplace_back(i);
    }
  }
  int ans = -1;
  dist_u(u);
  dist_v(v);
  for (auto nv : cand) {
    if (distance_u[nv] < distance_v[nv]) {
      ans = max(ans, distance_v[nv] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
