#include <bits/stdc++.h>
using namespace std;
vector<int> d[100001] = {};
int a[100001] = {}, aa[100001] = {}, t[100001] = {};
int dfs_a(int from, int now) {
  a[now] = a[from] + 1;
  aa[now] = aa[from] + 1;
  for (auto p : d[now]) {
    if (p == from)
      continue;
    else
      dfs_a(now, p);
  }
}
int dfs_t(int from, int now) {
  t[now] = t[from] + 1;
  for (auto p : d[now]) {
    if (p == from)
      continue;
    else
      dfs_t(now, p);
  }
}
int main() {
  int n, u, v, ans = 0;
  cin >> n >> u >> v;
  for (int(i) = 0; i < (n); i++) {
    int s, t;
    cin >> s >> t;
    d[s].push_back(t);
    d[t].push_back(s);
  }
  for (auto p : d[v]) dfs_a(v, p);
  for (auto p : d[u]) dfs_t(u, p);
  sort(aa, aa + 100001, greater<int>());
  int bf = 0;
  for (int(i) = 0; i < (100001); i++) {
    for (int(j) = 0; j < (100001); j++) {
      if (aa[i] == a[j]) {
        if (a[j] <= t[j]) {
          break;
        } else {
          ans = a[j] - 1;
          bf = 1;
          break;
        }
      } else
        j++;
    }
    if (bf) break;
  }
  cout << ans;
}
