#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
vector<vector<long long>> edge;
long long aoki[100008];
void dfs(long long at, long long t) {
  aoki[at] = t;
  for (long long i = (0); i < (edge[at].size()); i++) {
    long long next = edge[at][i];
    if (aoki[next] == -1) {
      dfs(next, t + 1);
    }
  }
}
long long dfs2(long long from, long long at, long long t) {
  if (aoki[at] == t) {
    return t;
  }
  if (aoki[at] == t - 1) {
    return t - 1;
  }
  long long res = t;
  bool keep = false;
  for (long long i = (0); i < (edge[at].size()); i++) {
    long long next = edge[at][i];
    if (aoki[next] > t + 1 && aoki[at] >= t + 2) {
      keep = true;
    }
    if (aoki[next] > t && next != from) {
      long long buf = dfs2(at, next, t + 1);
      res = max(buf, res);
    }
  }
  if (keep) {
    long long buf = dfs2(-1, at, t + 2);
    res = max(buf, res);
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, u, v;
  cin >> n >> u >> v;
  edge.resize(n + 1);
  long long a, b;
  for (long long i = (0); i < (n); i++) {
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for (long long i = (1); i < (n + 1); i++) {
    aoki[i] = -1;
  }
  dfs(v, 0);
  long long ans = dfs2(-1, u, 0);
  cout << (ans) << endl;
  return 0;
}
