#include <bits/stdc++.h>
using namespace std;
const int MAXV = (int)1e5 + 1;
const int INF = (int)1e8;
struct edge {
  int to;
};
vector<edge> G[MAXV];
int Takahashi[MAXV];
int Aoki[MAXV];
bool visited[MAXV];
int d[MAXV];
int previous[MAXV];
int Aoki_distance(int i, int count) {
  if (Aoki[i] < 0) {
    Aoki[i] = count;
    count++;
  }
  for (auto& e : G[i]) {
    if (Aoki[e.to] < 0) {
      Aoki_distance(e.to, count);
    }
  }
  return 0;
}
using P = pair<int, int>;
bool dijkstra(int s, int goal, int N) {
  fill(d, d + MAXV, INF);
  fill(previous, previous + MAXV, -1);
  d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + 1) {
        d[e.to] = d[v] + 1;
        previous[e.to] = v;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  vector<int> route;
  for (int ii = goal; ii != -1; ii = previous[ii]) {
    route.push_back(ii);
  }
  for (int ii = 0; ii < (int)route.size() - 1; ii++) {
    if (d[route[ii]] >= Aoki[route[ii]]) {
      return false;
    } else {
      visited[ii] = true;
    }
  }
  return true;
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  int a[N - 1], b[N - 1];
  priority_queue<pair<int, int>> que;
  for (int i = 0; i < N - 1; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i <= N; i++) {
    Takahashi[i] = -1;
    Aoki[i] = -1;
  }
  for (int i = 0; i < N - 1; i++) {
    edge e = {b[i]};
    G[a[i]].push_back(e);
    e = {a[i]};
    G[b[i]].push_back(e);
  }
  Aoki_distance(v, 0);
  fill(visited, visited + MAXV, false);
  for (int i = 1; i <= N; i++) {
    que.push(make_pair(Aoki[i], i));
  }
  int goal;
  while (!que.empty()) {
    goal = que.top().second;
    que.pop();
    if (visited[goal]) continue;
    if (dijkstra(u, goal, N)) break;
  }
  if (Aoki[goal] == 0) {
    cout << 0 << endl;
  } else {
    cout << Aoki[goal] - 1 << endl;
  }
  return 0;
}
