#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 100005;
vector<int> adjList[MAXN];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10),
      cout << fixed;
  int n, a, b;
  cin >> n >> a >> b;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  if (a == b) {
    cout << 0 << '\n';
    return 0;
  }
  queue<int> q1, q2;
  q1.push(a);
  q2.push(b);
  vector<int> vis(n + 1, 0);
  vis[a] = 1;
  vis[b] = 2;
  int moves = 1;
  int ans = 0;
  while (!q2.empty()) {
    if (moves & 1) {
      int sz = q1.size();
      while (sz--) {
        auto u = q1.front();
        q1.pop();
        if (vis[u] == 2) continue;
        bool f = false;
        for (auto v : adjList[u]) {
          if (!vis[v] || vis[v] == 2) {
            if (vis[v]) {
              ans = max(ans, moves / 2);
            } else {
              f = true;
              vis[v] = 1;
              q1.push(v);
            }
          }
        }
        if (f)
          vis[u] = 0;
        else
          vis[u] = 2;
      }
    } else {
      int sz = q2.size();
      while (sz--) {
        auto u = q2.front();
        q2.pop();
        for (auto v : adjList[u]) {
          if (!vis[v] || vis[v] == 1) {
            if (vis[v]) ans = max(ans, moves / 2);
            vis[v] = 2;
            q2.push(v);
          }
        }
      }
    }
    ++moves;
  }
  cout << ans << '\n';
  return 0;
}
