#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<int> edge[maxn];
int n;
int sp[2][maxn];
bool book[maxn];
void dfs(int u, int cr, int dep) {
  book[u] = true;
  sp[cr][u] = dep;
  for (size_t i = 0; i < edge[u].size(); i++) {
    register int cv = edge[u][i];
    if (!book[cv]) dfs(cv, cr, dep + 1);
  }
}
int main() {
  int cu, cv, u, v, ans = 0;
  scanf("%d%d%d", &n, &u, &v);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &cu, &cv);
    edge[cu].push_back(cv);
    edge[cv].push_back(cu);
  }
  if (edge[u].size() == 1 && edge[u][0] == v) {
    puts("0");
    return 0;
  }
  dfs(v, 0, 0);
  memset(book, 0, sizeof(book));
  dfs(u, 1, 0);
  for (int i = 1; i <= n; i++)
    if (edge[i].size() == 1 && sp[0][i] >= sp[1][i])
      ans = max(ans, (sp[0][i] - sp[1][i]) / 2 + sp[1][i]);
  printf("%d\n", ans);
  return 0;
}
