#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int64_t>> edges(N);
  for (int64_t i = 0; i < N - 1; i++) {
    int64_t A, B;
    cin >> A >> B;
    A--;
    B--;
    edges[A].push_back(B);
    edges[B].push_back(A);
  }
  vector<int64_t> cost_from_v(N);
  stack<pair<int64_t, int64_t>> st;
  st.push({v, -1});
  cost_from_v[v] = 0;
  while (!st.empty()) {
    pair<int64_t, int64_t> top = st.top();
    st.pop();
    for (int64_t next_node : edges[top.first]) {
      if (next_node == top.second) {
        continue;
      }
      st.push({next_node, top.first});
      cost_from_v[next_node] = cost_from_v[top.first] + 1;
    }
  }
  vector<int64_t> cost_from_u(N);
  st.push({u, -1});
  cost_from_u[u] = 0;
  while (!st.empty()) {
    pair<int64_t, int64_t> top = st.top();
    st.pop();
    for (int64_t next_node : edges[top.first]) {
      if (next_node == top.second) {
        continue;
      }
      st.push({next_node, top.first});
      cost_from_u[next_node] = cost_from_u[top.first] + 1;
    }
  }
  int64_t ans = LLONG_MIN;
  for (int64_t i = 0; i < N; i++) {
    if (cost_from_v[i] < cost_from_u[i]) {
      continue;
    }
    int64_t diff = cost_from_u[i] - cost_from_v[i];
    if (diff % 2 == 0) {
      ans = max(ans, cost_from_v[i]);
    } else {
      ans = max(ans, cost_from_v[i] - (edges[i].size() == 1));
    }
  }
  cout << ans << endl;
}
