#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> dt, da;

void dfs(int x, int par, vector<int> &dist) {
  dist[x] = dist[par] + !(x == par);
  for (auto to : g[x]) {
    if (to == par)  continue;
    dfs(to, x, dist);
  }
}

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, t, a;
  cin >> n >> t >> a;

  g.resize(n + 5);
  dt.assign(n + 5, 0);
  da.assign(n + 5, 0);

  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;

    g[u].push_back(v);
    g[v].push_back(u);
  }

  dfs(t, t, dt);
  dfs(a, a, da);

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (dt[i] < da[i])
      ans = max(ans, da[i] - 1); 
  }

  cout << ans << '\n';
}