#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int N, T, A;
vector<int> G[100010];
int da[100010];
int ans;
void Dfs(int p, int pre, int len, int d[]) {
  d[p] = len;
  for (int i = 0; i <= ((int)(G[p]).size()) - 1; ++i) {
    int v = G[p][i];
    if (v == pre) continue;
    Dfs(v, p, len + 1, d);
  }
}
void Dfs2(int p, int pre, int len) {
  if (da[p] + 1 == len || da[p] == len) {
    ans = max(da[p], ans);
    return;
  }
  for (int i = 0; i <= ((int)(G[p]).size()) - 1; ++i) {
    int v = G[p][i];
    Dfs2(v, p, len + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> T >> A;
  for (int i = 1; i <= N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  Dfs(A, -1, 0, da);
  Dfs2(T, -1, 0);
  cout << ans << endl;
  return 0;
}
