#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
int main(void) {
  int n, u, v, i, j, a, b, d[100003] = {}, p, par[100003], lim, dmax;
  vector<int> g[100003];
  queue<int> q, th;
  scanf("%d%d%d", &n, &u, &v);
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  q.push(v - 1);
  d[v - 1] = 1;
  while (!q.empty()) {
    p = q.front();
    q.pop();
    for (i = 0; i < g[p].size(); i++) {
      if (d[g[p][i]] == 0) {
        d[g[p][i]] = d[p] + 1;
        q.push(g[p][i]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < g[i][j]; j++) {
      if (d[i] < d[g[i][j]]) {
        par[g[i][j]] = i;
      }
    }
  }
  i = v - 1;
  lim = (d[v - 1] + 1) / 2 + 1;
  while (d[i] > lim) {
    i = par[i];
  }
  th.push(i);
  while (!th.empty()) {
    p = th.front();
    th.pop();
    dmax = max(dmax, d[p]);
    for (i = 0; i < g[p].size(); i++) {
      if (d[p] < d[g[p][i]]) {
        th.push(g[p][i]);
      }
    }
  }
  printf("%d\n", dmax - 2);
  return 0;
}
