#include <bits/stdc++.h>
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;
}
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return n != 1;
}
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const long long MAX_N = 100010;
vector<long long> to[100010];
long long n;
vector<long long> dist;
void dfs(long long v, long long d = 0, long long p = -1) {
  for (long long u : to[v]) {
    if (u == p) continue;
    dfs(u, d + 1, v);
  }
}
vector<long long> calcdist(long long s) {
  dist = vector<long long>(n);
  dfs(s);
  return dist;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long s, t;
  cin >> s >> t;
  s--;
  t--;
  for (long long i = 0; i < (n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<long long> dists = calcdist(s);
  vector<long long> distt = calcdist(t);
  long long M = 0;
  for (long long i = 0; i < (n); i++) {
    if (dists[i] < distt[i]) {
      chmax(M, distt[i]);
    }
  }
  cout << M - 1 << endl;
  return 0;
}
