#include <bits/stdc++.h>
using namespace std;
using Pair = pair<long long, pair<int, int>>;
const long long mod = 1000000007;
const long double pi = acos(-1.0);
const long long INF = 1LL << 61;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, s, t;
  cin >> n >> s >> t;
  s--;
  t--;
  vector<vector<int>> g(n);
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> dis(n, -1);
  deque<int> que;
  dis[t] = 0;
  que.push_back(t);
  while (!que.empty()) {
    int v = que.front();
    que.pop_front();
    for (int nv : g[v]) {
      if (dis[nv] != -1) continue;
      dis[nv] = dis[v] + 1;
      que.push_back(nv);
    }
  }
  vector<int> dist(n, -1);
  dist[s] = 0;
  que.push_back(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop_front();
    for (int nv : g[v]) {
      if (dist[nv] != -1 || dist[v] + 1 > dis[nv]) continue;
      dist[nv] = dist[v] + 1;
      if (dist[nv] < dis[nv]) que.push_back(nv);
    }
  }
  int ans = -1;
  for (int i = 0; i < (int)(n); i++) {
    chmax(ans, dist[i]);
  }
  cout << ans << "\n";
}
