#include <bits/stdc++.h>
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
using ll = long long;
using namespace std;
int n, u, v;
int main() {
  cin >> n >> u >> v;
  vector<vector<int>> edges(n);
  for (int i = 0; i < (int)(n - 1); ++i) {
    int a, b;
    read_from_cin(a, b);
    ;
    --a, --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  map<int, int> aoki;
  aoki[v - 1] = 0;
  queue<int> que;
  que.push(v - 1);
  while (!que.empty()) {
    int here = que.front();
    que.pop();
    ;
    for (int there : edges[here]) {
      if (aoki.count(there)) continue;
      aoki[there] = aoki[here] + 1;
      que.push(there);
    }
  }
  map<int, int> takahashi;
  takahashi[u - 1] = 0;
  que.push(u - 1);
  int maxi = -1;
  while (!que.empty()) {
    int here = que.front();
    que.pop();
    ;
    for (int there : edges[here]) {
      if (takahashi.count(there)) continue;
      if (aoki[there] <= takahashi[here] + 1) continue;
      takahashi[there] = takahashi[here] + 1;
      que.push(there);
      maxi = max(maxi, aoki[there]);
    }
  }
  if (maxi == -1) {
    if (aoki[u - 1] == 1) {
      write_to_cout(0);
      ;
    } else {
      write_to_cout(1);
      ;
    }
  } else {
    write_to_cout(maxi - 1);
    ;
  }
}
