#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
inline long long mul(long long a, long long b) {
  return (long long)((long long)a * b % 1000000007);
}
long long min(long long a, long long b) { return a > b ? b : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long n, u, v;
vector<long long> adj[200000];
bool visa[200000], vist[200000];
bool st[200000], sa[200000];
int main() {
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i += 1) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (int i = 0; i < n + 1; i += 1) vist[i] = 0, visa[i] = 0;
  for (int i = 0; i < n + 1; i += 1) st[i] = 0, sa[i] = 0;
  sa[v] = 1;
  st[u] = 1;
  if (u == v) {
    cout << 0 << "\n";
    return 0;
  }
  long long cnt1 = 1;
  queue<long long> t, a, t2, a2;
  t.push(u);
  vist[u] = 1;
  a.push(v);
  visa[v] = 1;
  long long cnt = 0;
  while (cnt1 > 0) {
    while (!t.empty()) {
      long long top = t.front();
      t.pop();
      cnt1--;
      st[top] = 0;
      if ((int)((adj[top]).size()) == 1) {
        if (!sa[adj[top][0]]) {
          vist[top] = 0;
          cnt1++;
          t2.push(adj[top][0]);
          vist[adj[top][0]] = 1;
          st[adj[top][0]] = 1;
        }
        continue;
      }
      for (int i = 0; i < (int)((adj[top]).size()); i += 1) {
        if (sa[adj[top][i]]) continue;
        if (st[adj[top][i]]) continue;
        if (vist[adj[top][i]]) continue;
        st[adj[top][i]] = 1;
        t2.push(adj[top][i]);
        vist[adj[top][i]] = 1;
        cnt1++;
      }
    }
    while (!t2.empty()) {
      t.push(t2.front());
      t2.pop();
    }
    if (cnt1 == 0) break;
    cnt++;
    while (!a.empty()) {
      long long top = a.front();
      a.pop();
      sa[top] = 0;
      for (int i = 0; i < (int)((adj[top]).size()); i += 1) {
        long long j = adj[top][i];
        if (st[j] == 1 && cnt1 == 1) {
          cnt1 = 0;
          break;
        }
        if (visa[j]) continue;
        a2.push(j);
        sa[j] = 1;
        visa[j] = 1;
      }
    }
    while (!a2.empty()) {
      a.push(a2.front());
      a2.pop();
    }
  }
  cout << cnt << "\n";
}
