#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int n, taka, aoki;
vector<int> G[100010];
int d[100010] = {0};
bool visited[10010] = {0};
int tsd = -1, asd = -1, ts, as;
bool dfs1(int i = taka, int depth = 0) {
  visited[i] = true;
  d[i] = depth;
  if (i == aoki) {
    tsd = (d[i] - 1) / 2;
    asd = (d[i] + 2) / 2;
    if (d[i] == asd) as = i;
    if (d[i] == tsd) ts = i;
    return true;
  }
  for (auto &g : G[i]) {
    if (visited[g]) continue;
    bool isChild = dfs1(g, depth + 1);
    if (isChild) {
      if (d[i] == asd) as = i;
      if (d[i] == tsd) ts = i;
      return true;
    }
  }
  return false;
}
int dfs2(int i = ts) {
  int ans = 0;
  visited[i] = true;
  if (i == as) return -1;
  for (auto &g : G[i]) {
    if (visited[g]) continue;
    int val = dfs2(g);
    if (val < 0 && i != ts) return -1;
    ans = max(ans, val + 1);
  }
  return ans;
}
int main() {
  cin >> n >> taka >> aoki;
  taka--;
  aoki--;
  for (int i = 0, a, b; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs1();
  fill(visited, visited + n, false);
  cout << dfs2() + tsd + !(d[aoki] % 2) << '\n';
  return 0;
}
