#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, s, t;
  cin >> n >> s >> t;
  vector<vector<int>> G(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  function<void(int, int, vector<int>& dis, vector<int>& path)> dfs =
      [&](int u, int p, vector<int>& dis, vector<int>& path) -> void {
    dis[u] = dis[p] + 1;
    for (int v : G[u]) {
      if (v == p) continue;
      path[v] = u;
      dfs(v, u, dis, path);
    }
  };
  vector<int> path_s(n + 1), path_t(n + 1);
  vector<int> dis_s(n + 1), dis_t(n + 1);
  dfs(s, 0, dis_s, path_s);
  dfs(t, 0, dis_t, path_t);
  int go = -1;
  int ds = -1;
  for (int i = 1; i <= n; i++) {
    if (i == s or i == t) continue;
    if (dis_s[i] < dis_t[i] and dis_s[i] > ds) {
      ds = dis_s[i];
      go = i;
    }
  }
  if (go == -1) {
    s = G[s][0];
    cout << (s != t) << '\n';
    return (0);
  }
  deque<int> p_s, p_t;
  int tmp = go;
  p_s.push_back(tmp);
  while (tmp != s) p_s.push_back(path_s[tmp]), tmp = path_s[tmp];
  tmp = go;
  p_t.push_back(tmp);
  while (tmp != t) p_t.push_back(path_t[tmp]), tmp = path_t[tmp];
  reverse(begin(p_s), end(p_s));
  reverse(begin(p_t), end(p_t));
  p_s.pop_front();
  p_t.pop_front();
  int prev = s;
  int ans = 0;
  while (s != go) {
    prev = s;
    s = p_s.front();
    t = p_t.front();
    p_s.pop_front();
    p_t.pop_front();
    ans++;
  }
  while (!p_t.empty()) {
    swap(prev, s);
    if (s == t) break;
    t = p_t.front();
    p_t.pop_front();
    ans++;
  }
  cout << ans << '\n';
  return (0);
}
