#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int len[maxn], ord[maxn];
vector<int> gr[maxn];
int fin[maxn];
int dfs1(int node, int anc, int lev) {
  if (anc != 0) fin[node] = anc;
  ord[node] = lev;
  len[node] = lev;
  for (auto it : gr[node]) {
    if (it != anc) len[node] = max(len[node], dfs1(it, node, lev + 1));
  }
  return len[node];
}
int main() {
  int n, beg, tar, x, y;
  scanf("%d%d%d", &n, &beg, &tar);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  dfs1(y, 0, 0);
  int lev = 0, node = x, ma = 0;
  while (ord[node] > lev) {
    ma = max(ma, len[node]);
    lev++;
    node = fin[node];
  }
  printf("%d", ma - 1);
}
