#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> friends[maxn], zeros, vt;
int que[maxn], dis[maxn], down_dis[maxn], fa[maxn], n, u, v;
bool vis[maxn], ok[maxn];
int get_lca(int a, int b) {
  if (dis[a] > dis[b]) swap(a, b);
  int tmpa = a, tmpb = b;
  for (int i = dis[b]; i > dis[a]; i--) tmpa = fa[tmpa];
  while (tmpa != tmpb) {
    tmpa = fa[tmpa];
    tmpb = fa[tmpb];
  }
  return tmpa;
}
void get_dis(int u) {
  int head = 0, tail = 0;
  que[tail] = u;
  dis[u] = 0;
  tail++;
  vis[u] = true;
  fa[u] = 0;
  while (head < tail) {
    int x = que[head];
    head++;
    for (int i = 0; i < friends[x].size(); i++) {
      if (vis[friends[x][i]]) continue;
      int tmp = friends[x][i];
      vis[tmp] = true;
      dis[tmp] = dis[x] + 1;
      que[tail] = tmp;
      tail++;
      fa[tmp] = x;
    }
  }
}
void get_zeros() {
  for (int i = 1; i <= n; i++)
    if (friends[i].size() == 1 && i != u) zeros.push_back(i);
}
void get_down_dis(int u) {
  memset(que, 0, sizeof(que));
  memset(vis, 0, sizeof(vis));
  memset(down_dis, -1, sizeof(down_dis));
  int head = 0, tail = 0;
  for (int i = 0; i < zeros.size(); i++) {
    que[tail] = zeros[i];
    tail++;
    down_dis[zeros[i]] = 0;
    vis[zeros[i]] = true;
  }
  while (head < tail) {
    int x = que[head];
    head++;
    if (x == u) continue;
    down_dis[fa[x]] = max(down_dis[fa[x]], down_dis[x] + 1);
    if (!vis[fa[x]]) {
      que[tail] = fa[x];
      vis[fa[x]] = true;
      tail++;
    }
  }
}
void get_vt(int u, int v) {
  vt.push_back(v);
  int tmpv = v;
  for (int i = dis[v]; i > dis[u]; i--) vt.push_back(tmpv = fa[tmpv]);
  reverse(vt.begin(), vt.end());
}
int solve_others(int u, int v, int num) {
  int ans = -maxn, td = vt.size() - 1;
  for (int i = 0; i < friends[u].size(); i++) {
    if (friends[u][i] == fa[u] || friends[u][i] == vt[num + 1]) continue;
    ans = max(ans, down_dis[friends[u][i]] + td - num);
  }
  return ans;
}
int solve_all(int u, int v) {
  int ans = solve_others(u, v, vt.size() - 1);
  for (int i = 1; i <= (vt.size() - 2) / 2; i++)
    ans = max(ans, solve_others(vt[i], v, i));
  ans = max(ans, (int)(vt.size() - 2));
  return ans;
}
void run() {
  get_dis(u);
  get_zeros();
  get_down_dis(u);
  get_vt(u, v);
  int ans = solve_all(u, v);
  printf("%d\n", ans);
}
void fl() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int main() {
  scanf("%d%d%d", &n, &u, &v);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    friends[a].push_back(b);
    friends[b].push_back(a);
  }
  run();
  return 0;
}
