#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MAX = 2000000;
long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a;
  x = 1;
  y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  int A[N - 1], B[N - 1];
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i];
  }
  vector<vector<int> > graph(N + 1);
  for (int i = 0; i < N - 1; i++) {
    graph[A[i]].push_back(B[i]);
    graph[B[i]].push_back((A[i]));
  }
  int aoki[N + 1];
  for (int i = 0; i < N + 1; i++) {
    aoki[i] = -1;
  }
  aoki[0] = MAX;
  aoki[v] = 0;
  queue<int> bfs;
  bfs.push(v);
  while (!bfs.empty()) {
    int l = bfs.front();
    bfs.pop();
    for (int i = 0; i < graph[l].size(); i++) {
      if (aoki[graph[l][i]] == -1) {
        aoki[graph[l][i]] = aoki[l] + 1;
        bfs.push(graph[l][i]);
      }
    }
  }
  int takahashi[N + 1];
  for (int i = 0; i < N + 1; i++) {
    takahashi[i] = -1;
  }
  takahashi[0] = MAX;
  takahashi[u] = 0;
  bfs.push(u);
  while (!bfs.empty()) {
    int l = bfs.front();
    bfs.pop();
    for (int i = 0; i < graph[l].size(); i++) {
      if (takahashi[graph[l][i]] == -1) {
        takahashi[graph[l][i]] = takahashi[l] + 1;
        bfs.push(graph[l][i]);
      }
    }
  }
  pair<int, int> aokii[N + 1];
  pair<int, int> takahashii[N + 1];
  for (int i = 0; i < N + 1; i++) {
    aokii[i] = make_pair(aoki[i], i);
    takahashii[i] = make_pair(takahashi[i], i);
  }
  sort(aokii, aokii + N + 1);
  reverse(aokii, aokii + N + 1);
  sort(takahashii, takahashii + N + 1);
  reverse(takahashii, takahashii + N + 1);
  int mokutekiti = -1;
  for (int i = 0; i < N + 1; i++) {
    if (aokii[i].first == 200000 || takahashi[aokii[i].second] == 200000) {
      continue;
    }
    if (aokii[i].first > takahashi[aokii[i].second]) {
      mokutekiti = aokii[i].second;
      break;
    }
  }
  if ((aoki[mokutekiti] - takahashi[mokutekiti]) % 2 == 0 &&
      takahashi[mokutekiti] != 0) {
    cout << aoki[mokutekiti] << endl;
  } else {
    cout << aoki[mokutekiti] - 1 << endl;
  }
}
