#include <bits/stdc++.h>
using namespace std;
int n, u, v;
int a[100005], b[100005];
vector<int> V[1000005];
vector<pair<int, int>> takahashi, aoki;
void input() {
  cin >> n >> u >> v;
  for (int i = 1; i < n; ++i) {
    cin >> a[i] >> b[i];
    V[a[i]].push_back(b[i]);
    V[b[i]].push_back(a[i]);
  }
}
int aokicnt[100005];
void bfs1(int root) {
  int flag[1000005], cnt[100005];
  for (int i = 1; i < n; ++i) {
    flag[i] = 0;
    cnt[i] = 0;
    aokicnt[i] = 100005;
  }
  queue<int> Q;
  flag[root] = 1;
  aokicnt[root] = 0;
  Q.push(root);
  while (!Q.empty()) {
    int tmp = Q.front();
    Q.pop();
    for (int i = 0; i < V[tmp].size(); ++i) {
      if (!flag[V[tmp][i]]) {
        flag[V[tmp][i]] = 1;
        Q.push(V[tmp][i]);
        cnt[V[tmp][i]] = cnt[tmp] + 1;
        aokicnt[V[tmp][i]] = min(cnt[tmp] + 1, aokicnt[V[tmp][i]]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    aoki.push_back(make_pair(cnt[i], i));
  }
  sort(aoki.begin(), aoki.end());
}
int flag2[100005];
int bfs2(int root, int goal) {
  int flag[100005], cnt[100005];
  for (int i = 1; i <= n; ++i) {
    flag[i] = 0;
    flag2[i] = 0;
    cnt[i] = 100005;
  }
  queue<int> Q;
  flag[root] = 1;
  cnt[root] = 0;
  Q.push(root);
  while (!Q.empty()) {
    int tmp = Q.front();
    Q.pop();
    for (int i = 0; i < V[tmp].size(); ++i) {
      if (!flag[V[tmp][i]]) {
        flag2[tmp] = 1;
        flag[V[tmp][i]] = 1;
        Q.push(V[tmp][i]);
        cnt[V[tmp][i]] = min(cnt[tmp] + 1, cnt[V[tmp][i]]);
      }
    }
  }
  return cnt[goal];
}
int main() {
  input();
  bfs1(v);
  int nige = u;
  for (int i = aoki.size() - 1; i >= 0; --i) {
    if (aoki[i].first > aokicnt[aoki[i].second] && flag2[aoki[i].second] != 1) {
      nige = aoki[i].second;
      break;
    }
  }
  int ans = 0;
  ans = bfs2(v, nige);
  cout << ans - 1 << endl;
}
