#include <bits/stdc++.h>
using namespace std;
int dist[100004];
int dist1[100004];
vector<int> v[100004];
void dis(int n, int i) {
  dist[i] = n;
  for (auto j : v[i]) {
    if (dist[j] != -1) continue;
    dis(n + 1, j);
  }
}
void dis1(int n, int i) {
  dist1[i] = n;
  for (auto j : v[i]) {
    if (dist1[j] != -1) continue;
    dis1(n + 1, j);
  }
}
int main() {
  long long n, a, b, p, q;
  cin >> n >> a >> b;
  memset(dist, -1, sizeof(dist));
  memset(dist1, -1, sizeof(dist1));
  for (int i = 0; i < n; i++) {
    cin >> p >> q;
    v[p].push_back(q);
    v[q].push_back(p);
  }
  if (p == q) {
    cout << 0;
    return 0;
  }
  dis(0, a);
  dis1(0, b);
  p = 0, q = -1;
  for (int i = 1; i <= n; i++) {
    if (dist1[i] <= dist[i]) {
      continue;
    }
    if (dist1[i] + dist[i] > p) {
      p = dist1[i] + dist[i];
      q = i;
    }
  }
  if (dist1[q] == 2)
    cout << 1;
  else
    cout << dist1[q] - 2 + dist1[q] - dist[q];
  return 0;
}
