#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, rob, pol;
int police[N], robbery[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> n >> rob >> pol;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  memset(police, -1, sizeof police);
  queue<int> q;
  police[pol] = 0;
  q.push(pol);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int nxt : adj[u]) {
      if (police[nxt] == -1) {
        police[nxt] = police[u] + 1;
        q.push(nxt);
      }
    }
  }
  int ans = 0;
  robbery[rob] = 0;
  q.push(rob);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int nxt : adj[u]) {
      if (robbery[nxt] == -1 && robbery[u] + 1 == police[nxt]) {
        ans = max(ans, police[nxt]);
      }
      if (robbery[nxt] == -1 && robbery[u] + 1 < police[nxt]) {
        robbery[nxt] = robbery[u] + 1;
        q.push(nxt);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (robbery[i] != -1) {
      ans = max(ans, police[i] - 1);
    }
  }
  cout << ans << '\n';
  return 0;
}
