#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, u, v, a, b;
  vector<vector<int> > g(100010);
  cin >> n >> u >> v;
  u--, v--;
  for (i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int INF = (1 << 29);
  vector<int> x(100010, INF);
  vector<int> y(100010, INF);
  stack<int> s;
  s.push(u);
  x[u] = 0;
  while (!s.empty()) {
    int v = s.top();
    s.pop();
    for (i = 0; i < g[v].size(); i++) {
      if (x[g[v][i]] > x[v] + 1) {
        s.push(g[v][i]);
        x[g[v][i]] = x[v] + 1;
      }
    }
  }
  s.push(v);
  y[v] = 0;
  while (!s.empty()) {
    int v = s.top();
    s.pop();
    for (i = 0; i < g[v].size(); i++) {
      if (y[g[v][i]] > y[v] + 1) {
        s.push(g[v][i]);
        y[g[v][i]] = y[v] + 1;
      }
    }
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    ans = max(ans, min(x[i], y[i]));
  }
  for (i = 0; i < n; i++) {
    if (x[i] == y[i]) {
      ans = min(ans, x[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
