#include <bits/stdc++.h>
using namespace std;
const int N = 200010, mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; };
int n;
int u, v;
int e[N], ne[N], h[N], idx;
int dis[N];
bool st[N];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
void get_dis() {
  queue<int> q;
  q.push(v);
  st[v] = true;
  dis[v] = 0;
  while (q.size()) {
    int t = q.front();
    q.pop();
    for (int i = h[t]; ~i; i = ne[i]) {
      int j = e[i];
      if (st[j]) continue;
      q.push(j);
      dis[j] = dis[t] + 1;
      st[j] = true;
    }
  }
}
int ans = 0;
void dfs(int u, int sum, int p) {
  if (sum >= dis[u]) {
    ans = max(dis[u], ans);
    return;
  }
  bool flag = true;
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    if (j != p) {
      dfs(j, sum + 1, u);
      flag = false;
    }
  }
  if (flag) ans = max(ans, dis[u] - 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(h, -1, sizeof h);
  cin >> n >> u >> v;
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b), add(b, a);
  }
  get_dis();
  dfs(u, 0, -1);
  cout << ans << endl;
  return 0;
}
