#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  vector<int> dist_a(N + 1, -1), dist_t(N + 1, -1);
  Graph G(N + 1);
  for (ll i = 0; i < (ll)(N - 1); i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if (G[u].size() == 1 && G[u].at(0) == v) {
    cout << 0 << endl;
    return 0;
  }
  dist_a[v] = 0;
  queue<int> Q;
  Q.push(v);
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    for (auto next_v : G[now]) {
      if (dist_a[next_v] != -1) continue;
      dist_a[next_v] = dist_a[now] + 1;
      Q.push(next_v);
    }
  }
  dist_t[v] = 0;
  queue<int> Qt;
  Qt.push(v);
  while (!Qt.empty()) {
    int now = Qt.front();
    Qt.pop();
    for (auto next_v : G[now]) {
      if (dist_t[next_v] != -1) continue;
      dist_t[next_v] = dist_t[now] + 1;
      Qt.push(next_v);
    }
  }
  int distination = 0;
  int l = 0;
  for (ll i = 1; i <= (ll)(N); i++) {
    if (G[i].size() == 1) {
      if (dist_a[i] > l && dist_t[i] <= dist_a[i]) {
        distination = i;
        l = dist_a[i];
      }
    }
  }
  cout << l - 1 << endl;
}
