#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> G;
vector<int> dis_a, dis_t;

void dfs(int who, int cur, int prev, int d) {
  for (auto nx : G.at(cur)) {
    if (nx == prev) continue;
    if (who == 0) {
      dis_a.at(nx) = d + 1;
      dfs(0, nx, cur, d+1);
    }
    else {
      dis_t.at(nx) = d + 1;
      dfs(1, nx, cur, d+1);
    }
  }
}

int main() {
  int N, u, v; cin >> N >> u >> v;
  u--; v--;
  G.resize(N);
  for (int i = 0; i < N-1; i++) {
    int A, B; cin >> A >> B;
    A--; B--;
    G.at(A).push_back(B);
    G.at(B).push_back(A);
  }
  dis_a.assign(N, -1);
  dis_t.assign(N, -1);
  dis_a.at(v) = 0;
  dis_t.at(u) = 0;
  dfs(0, v, -1, 0);
  dfs(1, u, -1, 0);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dis_a.at(i) > dis_t.at(i)) ans = max(ans, dis_a.at(i));
  }
  cout << ans - 1 << endl;
}