#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  vector<vector<int> > V(n);
  vector<int> t_c(n, 1e9);
  vector<int> a_c(n, 1e9);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  t_c[u] = 0;
  a_c[v] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (auto k : V[a]) {
      if (t_c[k] != 1e9) continue;
      q.push(k);
      t_c[k] = t_c[a] + 1;
    }
  }
  q.push(v);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (auto k : V[a]) {
      if (a_c[k] != 1e9) continue;
      q.push(k);
      a_c[k] = a_c[a] + 1;
    }
  }
  queue<pair<int, int> > p;
  p.push({u, 0});
  int maxi = 0;
  while (!p.empty()) {
    auto a = p.front();
    maxi = max(maxi, a.second);
    p.pop();
    if (a_c[a.first] <= a.second) continue;
    for (auto k : V[a.first]) {
      if (a_c[k] > a.second) {
        p.push({k, a.second + 1});
      }
    }
  }
  cout << maxi << endl;
}
