#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, bool>;
using graph = map<int, vector<int>>;
void dfs(graph &G, vector<int> &depth, vector<bool> &seen, int v, int d) {
  seen[v] = true;
  d++;
  depth[v] = d;
  for (auto nv : G[v]) {
    if (seen[nv]) continue;
    dfs(G, depth, seen, nv, d);
  }
  d--;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  graph G;
  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);
  }
  vector<int> a(n, 0), t(n, 0);
  vector<bool> seen(n, false);
  dfs(G, a, seen, v - 1, 0);
  seen.resize(n, false);
  dfs(G, t, seen, u - 1, 0);
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (a[i] > t[i])
      ;
    ans = max(ans, a[i]);
  }
  cout << ans - 2 << endl;
  return 0;
}
