#include <bits/stdc++.h>
using namespace std;
inline unsigned long long int GCD(unsigned long long int a,
                                  unsigned long long int b) {
  while (b != 0) {
    unsigned long long int t = a % b;
    a = b;
    b = t;
  }
  return a;
}
inline unsigned long long int LCM(unsigned long long int a,
                                  unsigned long long int b) {
  return a * b / GCD(a, b);
}
inline unsigned long long int POW(unsigned long long int a,
                                  unsigned long long int b,
                                  unsigned long long int m = ULLONG_MAX) {
  unsigned long long int r = 1;
  while (b) {
    if (b & 1) r = r * a % m;
    b >>= 1;
    a = a * a % m;
  }
  return r;
}
int n, u, v;
vector<int> link[100005];
int maxDepth[100005];
bool visit[100005];
bool visit2[100005];
int rootOf[100005];
int answerDp[100005];
int dfs(int root) {
  visit[root] = true;
  for (int i : link[root]) {
    if (visit[i]) continue;
    rootOf[i] = root;
    maxDepth[root] = max(maxDepth[root], dfs(i) + 1);
  }
  visit[root] = false;
  return maxDepth[root];
}
int dfs2(int root, int mv) {
  if (maxDepth[root] == 0) return 0;
  if (answerDp[root]) return answerDp[root];
  visit2[root] = true;
  for (int i : link[root]) {
    if (visit2[i]) continue;
    if (maxDepth[i] < maxDepth[root]) {
      answerDp[root] = max(answerDp[root], dfs2(i, mv) + 1);
    } else {
      answerDp[root] = max(answerDp[root], dfs2(i, mv + 1) + 1);
    }
  }
  visit2[root] = false;
  return answerDp[root];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  cin >> (n) >> (u) >> (v);
  for (unsigned long long int(i) = 0; (i) < unsigned long long int(n); (i)++) {
    int(x), (y);
    cin >> (x) >> (y);
    link[x].push_back(y);
    link[y].push_back(x);
  }
  dfs(v);
  if (maxDepth[u] == 0 && maxDepth[v] == 1) {
    return cout << 0, 0;
  }
  int answer = maxDepth[v] - 1;
  int cnt = 1;
  int tu = rootOf[u];
  while (tu != v) {
    int depthOfV = maxDepth[v] - cnt;
    if (depthOfV <= maxDepth[tu]) break;
    answer = max(answer, depthOfV + cnt - 1);
    cnt++;
    tu = rootOf[tu];
  }
  return cout << answer, 0;
}
