#include <bits/stdc++.h>
using namespace std;
vector<int> get_dis(vector<vector<int>> &E, int start) {
  vector<int> dis(E.size(), 100000000);
  dis[start] = 0;
  queue<int> Q;
  Q.push(start);
  while (Q.size() != 0) {
    int from = Q.front();
    Q.pop();
    for (int i = 0; i < E[from].size(); i++) {
      int to = E[from][i];
      if (dis[to] != 100000000) continue;
      dis[to] = dis[from] + 1;
      Q.push(to);
    }
  }
  return dis;
}
int main() {
  int N;
  cin >> N;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  vector<vector<int>> E(N, vector<int>());
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> dis_u = get_dis(E, u), dis_v = get_dis(E, v);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dis_u[i] <= dis_v[i]) continue;
    ans = max(ans, dis_v[i] - 1);
  }
  cout << ans << endl;
  return 0;
}
