#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> seen;
vector<int> U, V;
void dfs(Graph G, vector<int> &U, int v, int num) {
  seen[v] = true;
  U[v] = num;
  num++;
  for (int next_v : G[v]) {
    if (seen[next_v]) continue;
    dfs(G, U, next_v, num);
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  Graph G(N + 1);
  U.assign(N + 1, 0);
  V.assign(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;
  seen.assign(N + 1, false);
  int num = 0;
  dfs(G, V, v, num);
  num = 0;
  seen.assign(N + 1, false);
  dfs(G, U, u, num);
  for (int i = 1; i <= N; i++) {
    if (V[i] > U[i]) {
      ans = max(ans, V[i]);
    }
  }
  ans--;
  cout << ans << endl;
}
