#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
int distA[100005], distT[100005];
bool odw[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int T, A;
  cin >> T >> A;
  for (int i = 1; i <= n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<pair<int, int>> Q;
  Q.push({T, 0});
  while (!Q.empty()) {
    int v = Q.front().first;
    int d = Q.front().second;
    Q.pop();
    if (odw[v]) continue;
    distT[v] = d;
    for (auto u : G[v]) {
      if (!odw[u]) Q.push({u, d + 1});
    }
  }
  for (int i = 1; i <= n; ++i) odw[i] = false;
  Q.push({A, 0});
  while (!Q.empty()) {
    int v = Q.front().first;
    int d = Q.front().second;
    Q.pop();
    if (odw[v]) continue;
    distA[v] = d;
    for (auto u : G[v]) {
      if (!odw[u]) Q.push({u, d + 1});
    }
  }
  int wynik = -1;
  for (int i = 1; i <= n; ++i) {
    if (distT[i] < distA[i]) {
      wynik = max(wynik, distA[i] - 1);
    }
  }
  cout << wynik << "\n";
}
