#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const long long MOD = 998244353;
const long long MAX = 1000000;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a > b) {
    return b;
  }
  return a;
}
int main() {
  long long u, v, N;
  cin >> N >> u >> v;
  vector<long long> g[MAX];
  for (int i = 1; i <= N - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long a[MAX];
  long long t[MAX];
  for (int i = 1; i <= N; i++) {
    a[i] = -1;
    t[i] = -1;
  }
  queue<long long> q;
  a[u] = 0;
  q.push(u);
  while (!q.empty()) {
    long long w = q.front();
    q.pop();
    for (int i = 0; i < g[w].size(); i++) {
      long long x = g[w][i];
      if (a[x] == -1) {
        a[x] = a[w] + 1;
      }
    }
  }
  t[v] = 0;
  q.push(v);
  while (!q.empty()) {
    long long w = q.front();
    q.pop();
    for (int i = 0; i < g[w].size(); i++) {
      long long x = g[w][i];
      if (t[x] == -1) {
        t[x] = t[w] + 1;
        q.push(x);
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    if (t[i] > a[i]) {
      ans = max(ans, t[i] - 1);
    }
  }
  cout << ans;
  system("PAUSE");
}
