#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1E5 + 100;
vector<int> gr[MAX_N];
vector<int> d1(MAX_N), d2(MAX_N);
vector<bool> good(MAX_N, true);
void dfs(int x, int p, vector<int> &d) {
  for (auto y : gr[x])
    if (y != p) {
      d[y] = d[x] + 1;
      dfs(y, x, d);
    }
}
int res = 0;
void dfs2(int x, int p) {
  if (!good[x]) return;
  res = max(res, d2[x]);
  for (auto y : gr[x])
    if (y != p) dfs2(y, x);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  dfs(u, -1, d1);
  dfs(v, -1, d2);
  for (int i = 0; i < n; i++)
    if (d2[i] <= d1[i]) good[i] = false;
  dfs2(u, -1);
  cout << res << "\n";
  return 0;
}
