#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
inline int in() {
  int x;
  cin >> x;
  return x;
}
template <class T>
void max_self(T &a, const T &b) {
  if (a < b) a = b;
}
template <class T>
void min_self(T &a, const T &b) {
  if (a > b) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, tPos, aPos;
  cin >> N >> tPos >> aPos;
  vector<vector<int>> adjList(N + 1);
  for (int rep = 0; rep < N; ++rep) {
    int oneV, secV;
    cin >> oneV >> secV;
    adjList[oneV].push_back(secV);
    adjList[secV].push_back(oneV);
  }
  vector<int> distance(N + 1, INF);
  queue<int> BFS;
  BFS.push(aPos);
  distance[aPos] = 0;
  while (!BFS.empty()) {
    int curPos = BFS.front();
    BFS.pop();
    for (int adj : adjList[curPos]) {
      if (distance[adj] > distance[curPos] + 1) {
        distance[adj] = distance[curPos] + 1;
        BFS.push(adj);
      }
    }
  }
  vector<int> _distance(N + 1, INF);
  int maxAllowed = 0;
  if (distance[tPos] > 0) {
    BFS.push(tPos);
    _distance[tPos] = 0;
  }
  while (!BFS.empty()) {
    int curPos = BFS.front();
    BFS.pop();
    max_self(maxAllowed, _distance[curPos]);
    for (int adj : adjList[curPos]) {
      if (_distance[adj] > _distance[curPos] + 1 &&
          distance[adj] > _distance[curPos] + 1) {
        _distance[adj] = _distance[curPos] + 1;
        BFS.push(adj);
      }
    }
  }
  cout << maxAllowed << endl;
  return 0;
}
