#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5;
std::vector<std::vector<int>> g;
int n;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int u, v;
  cin >> n;
  cin >> u >> v;
  u--, v--;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  queue<tuple<int, int, int>> q;
  q.emplace(1, u, 0);
  q.emplace(2, v, 0);
  vector<int> used(n);
  vector<int> dis(n);
  int ans = 0;
  used[u] = 1;
  dis[u] = 0;
  used[v] = 2;
  dis[v] = 0;
  while (q.size()) {
    int who, where, step;
    tie(who, where, step) = q.front();
    q.pop();
    for (auto j : g[where]) {
      if (who == 1) {
        if (used[j]) continue;
      } else {
        if (used[j] == who) continue;
        if (used[j] == 1 && step + 1 == dis[j]) {
          cout << step + 1 << endl;
          exit(0);
        }
        if (used[j] == 1 && g[j].size() == 1) {
          if (step % 2 == dis[j] % 2) {
            ans = max(ans, step + 1 - 1);
          } else {
            ans = max(ans, step + 1 - 1);
          }
        }
      }
      q.emplace(who, j, step + 1);
      used[j] = who;
      dis[j] = step + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
