#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;
};
using Graph = vector<vector<Edge>>;
const int INF = 1e9;
int main() {
  int N;
  cin >> N;
  int u, v;
  cin >> u >> v;
  u--, v--;
  Graph G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back({b});
    G[b].push_back({a});
  }
  vector<int> dist(N, INF);
  queue<int> que;
  que.emplace(u);
  dist[u] = 0;
  while (que.size() != 0) {
    int now = que.front();
    que.pop();
    for (auto e : G[now]) {
      if (dist[e.to] == INF) {
        dist[e.to] = dist[now] + 1;
        que.emplace(e.to);
      }
    }
  }
  int ans = 0;
  vector<int> a(N, INF);
  a[v] = 0;
  que.emplace(v);
  while (que.size() != 0) {
    int now = que.front();
    que.pop();
    if (dist[now] > a[now]) {
    } else if (dist[now] == a[now]) {
      ans = max(ans, a[now]);
      continue;
    } else {
      int tmp = 0;
      if ((a[now] - dist[now]) % 2 == 0) {
        tmp = a[now];
      } else {
        tmp = a[now] - 1;
      }
      ans = max(ans, tmp);
    }
    for (auto e : G[now]) {
      if (a[e.to] == INF) {
        a[e.to] = a[now] + 1;
        que.push(e.to);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
