#include <bits/stdc++.h>
using namespace std;
int n, u, v;
vector<vector<int>> edges;
vector<int> A, T;
void dfs(int u, int l, vector<int>& a) {
  a[u] = l;
  for (auto v : edges[u])
    if (a[v] == 0) {
      dfs(v, l + 1, a);
    }
}
void dfs2(int u, int l, int& sol) {
  T[u] = l;
  if (l <= A[u]) sol = max(sol, A[u]);
  for (int v : edges[u])
    if (!T[v]) {
      dfs2(v, l + 1, sol);
    }
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(15);
  if (argc == 2 && atoi(argv[1]) == 123456789) {
    freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
  }
  cin >> n >> u >> v;
  edges.resize(n + 1);
  A.resize(n + 1);
  T.resize(n + 1);
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    int x, y;
    cin >> x >> y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  dfs(v, 0, A);
  A[v] = 0;
  int sol = 1;
  dfs2(u, 0, sol);
  cout << sol - 1 << endl;
  if (argc == 2 && atoi(argv[1]) == 123456789)
    cerr << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
  return 0;
}
