#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> g;
vector<int> d;
int dfs(int v) {
  static vector<bool> visited(n, false);
  visited[v] = true;
  int res = -1;
  for (auto nx : g[v])
    if (!visited[nx]) res = max(res, dfs(nx));
  d[v] = res + 1;
  return res + 1;
}
signed main() {
  cin >> n;
  g.resize(n);
  d.resize(n);
  int u, v;
  cin >> u >> v;
  --u;
  --v;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(v);
  cout << (d[v] - d[u] - 1) << endl;
  return 0;
}
