#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 100005;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long fpow(long long b, long long exp, long long mod) {
  if (exp == 0) return 1;
  long long t = fpow(b, exp / 2, mod);
  if (exp & 1) return t * t % mod * b % mod;
  return t * t % mod;
}
long long divmod(long long i, long long j, long long mod) {
  i %= mod, j %= mod;
  return i * fpow(j, mod - 2, mod) % mod;
}
int N, U, V, dis1[MAXN], dis2[MAXN];
bool vis[MAXN];
vector<int> adj[MAXN];
void dfs1(int cur) {
  vis[cur] = true;
  for (int v : adj[cur]) {
    if (!vis[v]) {
      dis1[v] = dis1[cur] + 1;
      dfs1(v);
    }
  }
}
void dfs2(int cur) {
  vis[cur] = true;
  for (int v : adj[cur]) {
    if (!vis[v]) {
      dis2[v] = dis2[cur] + 1;
      dfs2(v);
    }
  }
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> N >> U >> V;
  for (int i = 0, a, b; i < N - 1; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs1(U);
  memset(vis, false, sizeof(vis));
  dfs2(V);
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (dis2[i] > dis1[i]) {
      ans = max(ans, dis2[i]);
    }
  }
  cout << ans - 1 << endl;
}
