#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;
int n;
void dijkstra(vector<vector<int>> &G, int s, vector<int> &d) {
  using P = pair<int, int>;
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d.begin(), d.end(), inf);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      int to = G[v][i];
      if (d[to] > d[v] + 1) {
        d[to] = d[v] + 1;
        que.push(P(d[to], to));
      }
    }
  }
}
int main() {
  int u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<vector<int>> graph(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  vector<int> du(n), dv(n);
  dijkstra(graph, u, du);
  dijkstra(graph, v, dv);
  int ans = -1, ans2 = -1;
  for (int i = 0; i < n; ++i) {
    if (du[i] == dv[i]) ans = max(ans, du[i]);
    if (abs(du[i] - dv[i]) == 1) ans2 = max({ans2, du[i], dv[i]});
  }
  if (ans != -1)
    cout << ans << endl;
  else
    cout << ans2 - 1 << endl;
  return 0;
}
