#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
vector<int> adj[MAX];
int d[MAX], x, y, ans;
void dfs(int src, int par) {
  for (auto i : adj[src]) {
    if (i == par) continue;
    d[i] = d[src] + 1;
    dfs(i, src);
  }
}
void game(int src, int par, int cur) {
  for (auto i : adj[src]) {
    if (d[i] == cur + 1) {
      ans = max(ans, cur + 1);
    }
    if (d[i] <= cur + 1) continue;
    game(i, src, cur + 1);
  }
  ans = max(ans, cur);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n >> x >> y;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(y, 0);
  game(x, 0, 0);
  cout << ans << endl;
  return 0;
}
