#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int gamma[100001];
long long int inv(long long int t) {
  long long int t2[36];
  t2[0] = 1;
  t2[1] = t;
  for (int i = 2; i < 36; i++) {
    t2[i] = (t2[i - 1] * t2[i - 1]) % MOD;
  }
  long long int ans = 1;
  long long int s = MOD - 2;
  int i = 1;
  while (s > 0) {
    if (s % 2 == 1) {
      ans = (ans * t2[i]) % MOD;
    }
    s = s / 2;
    i++;
  }
  return ans;
}
long long int C(long long int a, long long int b) {
  if (a == b or b == 0) {
    return 1;
  }
  long long int ans = gamma[a];
  ans = (ans * inv(gamma[b])) % MOD;
  ans = (ans * inv(gamma[a - b])) % MOD;
  return ans;
}
long long int gcd(long long int a, long long int b) {
  while (a != b) {
    if (b > a) {
      swap(a, b);
    }
    a = a - b;
  }
  return a;
}
int aoki[100000];
int takahasi[100000];
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> tree[100000];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    tree[a - 1].push_back(b - 1);
    tree[b - 1].push_back(a - 1);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tree[i].size(); j++) {
    }
  }
  int count = 0;
  queue<int> temp;
  int s = 0;
  for (int i = 0; i < 100000; i++) {
    takahasi[i] = -1;
    aoki[i] = -1;
  }
  takahasi[u] = 0;
  aoki[v] = 0;
  temp.push(u);
  int hoge = 10;
  while (count < n - 1) {
    s++;
    int u = temp.size();
    for (int i = 0; i < u; i++) {
      int g = temp.front();
      temp.pop();
      for (int j = 0; j < tree[g].size(); j++) {
        if (takahasi[tree[g][j]] == -1) {
          takahasi[tree[g][j]] = s;
          count++;
          temp.push(tree[g][j]);
        }
      }
    }
  }
  int x = temp.size();
  for (int i = 0; i < x; i++) {
    temp.pop();
  }
  temp.push(v);
  count = 0;
  s = 0;
  while (count < n - 1) {
    s++;
    int u = temp.size();
    for (int i = 0; i < u; i++) {
      int g = temp.front();
      temp.pop();
      for (int j = 0; j < tree[g].size(); j++) {
        if (aoki[tree[g][j]] == -1) {
          aoki[tree[g][j]] = s;
          count++;
          temp.push(tree[g][j]);
        }
      }
    }
  }
  cout << endl;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int t;
    if (takahasi[i] < aoki[i]) {
      if (aoki[i] - takahasi[i] % 2 == 0) {
        ans = max(ans, aoki[i] - 1);
      } else {
        ans = max(ans, takahasi[i]);
      }
    }
  }
  cout << ans << endl;
}
