#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
vector<int> edges[100005];
int from_goal[100005];
int dfs(int cur, int par, int goal) {
  if (cur == goal) {
    from_goal[cur] = 1;
    return 1;
  }
  for (int ch : edges[cur]) {
    if (ch == par) continue;
    int ret = dfs(ch, cur, goal);
    if (ret) {
      from_goal[cur] = ++ret;
      return ret;
    }
  }
  return -1;
}
int dfs2(int cur, int par, int ng) {
  int ret = 0;
  for (int ch : edges[cur]) {
    if (ch == par) continue;
    if (ch == ng) continue;
    ret = max(ret, dfs2(ch, cur, ng) + 1);
  }
  return ret;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  fill(from_goal, from_goal + n, 0);
  int distance = dfs(u, -1, v);
  int start_num = distance - distance / 2 + 1;
  int ng_num = start_num - 1;
  int start_node, ng_node;
  for (int i = 0; i < n; i++) {
    if (from_goal[i] == start_num) start_node = i;
    if (from_goal[i] == ng_num) ng_node = i;
  }
  int depth = dfs2(start_node, -1, ng_node);
  if (depth == 0) {
    if (distance % 2 == 0) {
      cout << 0 << '\n';
    } else {
      cout << 1 << '\n';
    }
    return 0;
  }
  if (distance % 2 == 0) {
    cout << depth + distance / 2 - 1 << '\n';
  } else {
    cout << depth + distance / 2 << '\n';
  }
  return 0;
}
