#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;
vector<int> g[MAX_N];
int U, V, N, len[MAX_N];
vector<int> v1, v2;
bool col[MAX_N], on[MAX_N];
int ans = 0;
bool get_between(int x, int t, int fa) {
  if (x == t) return true;
  for (int i = 0; i < g[x].size(); i++) {
    int to = g[x][i];
    if (to == fa) continue;
    if (get_between(to, t, x)) {
      if (x != U) v1.push_back(x);
      return true;
    }
  }
  return false;
}
int get_len(int fr, int x, int fa) {
  int ret = 1;
  col[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    int to = g[x][i];
    if (to == fa) continue;
    if (on[to] && to != fr) continue;
    int now = get_len(fr, to, x);
    ret = max(ret, now + 1);
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &N, &U, &V);
  U--;
  V--;
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  get_between(U, V, -1);
  ans = max(ans, ((int)v1.size() + 1) / 2);
  for (int i = 0; i < v1.size(); i++) on[v1[i]] = 1;
  on[U] = 1;
  on[V] = 1;
  reverse(v1.begin(), v1.end());
  for (int i = 0; i < v1.size() / 2; i++) {
    int x = v1[i];
    len[x] = get_len(x, x, x) - 1;
    ans = max(ans, len[x] + (int)v1.size() - i - 1);
  }
  int lenth2 = get_len(V, V, -1) - 1;
  if (lenth2 >= 0) ans = max(ans, lenth2 + (int)v1.size());
  printf("%d\n", ans);
  return 0;
}
