#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  vector<vector<int>> tree(n + 1);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    tree[a].emplace_back(b);
    tree[b].emplace_back(a);
  }
  queue<pair<int, int>> qa;
  qa.emplace(make_pair(v, 0));
  vector<int> dis_a(n + 1, -1);
  dis_a[v] = 0;
  while (!qa.empty()) {
    auto front = qa.front();
    qa.pop();
    for (auto e : tree[front.first]) {
      if (dis_a[e] < 0) {
        dis_a[e] = front.second + 1;
        qa.emplace(make_pair(e, front.second + 1));
      }
    }
  }
  queue<pair<int, int>> qb;
  qb.emplace(make_pair(u, 0));
  vector<int> dis_t(n + 1, -1);
  dis_t[v] = 0;
  while (!qb.empty()) {
    auto front = qb.front();
    qb.pop();
    for (auto e : tree[front.first]) {
      if (dis_t[e] < 0) {
        dis_t[e] = front.second + 1;
        qb.emplace(make_pair(e, front.second + 1));
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dis_a[i] > dis_t[i] && dis_t[i] >= 0) {
      ans = max(ans, dis_a[i]);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
