#include <bits/stdc++.h>
using namespace std;
long long K = 1000000007;
int MAX = 100000;
vector<int> Dis(MAX);
vector<int> Dis2(MAX);
int main() {
  int N;
  int U, V;
  cin >> N >> U >> V;
  U--;
  V--;
  vector<vector<int>> Way(N, vector<int>(0));
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    Way[A].push_back(B);
    Way[B].push_back(A);
  }
  for (int i = 0; i < N; i++) Dis[i] = -1;
  Dis[V] = 0;
  queue<int> Q;
  Q.push(V);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    int WSize = Way.at(x).size();
    for (int i = 0; i < WSize; i++) {
      int to = Way[x][i];
      if (Dis[to] == -1) {
        Dis[to] = Dis[x] + 1;
        Q.push(to);
      }
    }
  }
  for (int i = 0; i < N; i++) Dis2[i] = -1;
  Dis2[U] = 0;
  queue<int> Q2;
  Q2.push(V);
  while (!Q2.empty()) {
    int x = Q2.front();
    Q2.pop();
    int WSize = Way.at(x).size();
    for (int i = 0; i < WSize; i++) {
      int to = Way[x][i];
      if (Dis2[to] == -1) {
        Dis2[to] = Dis2[x] + 1;
        Q2.push(to);
      }
    }
  }
  int Max = 0;
  if (U == V) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (Dis[i] >= Dis2[i]) {
        Max = max(Max, Dis[i]);
      }
    }
    cout << Max - 1;
  }
}
