#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
int dist[2][100005];
int ans = 0;
void dfs(int parent, int cur, int idx) {
  for (auto nx : G[cur]) {
    if (nx == parent) continue;
    dist[idx][nx] = dist[idx][cur] + 1;
    dfs(cur, nx, idx);
  }
}
void dfs2(int parent, int cur) {
  if (dist[0][cur] <= dist[1][cur]) {
    ans = max(ans, dist[1][cur]);
  }
  for (auto nx : G[cur]) {
    if (nx == parent) continue;
    if (dist[0][nx] < dist[1][nx]) {
      ans = max(ans, dist[1][nx]);
      dfs2(cur, nx);
    }
  }
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--, v--;
  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);
  }
  dfs(u, u, 0);
  dfs(v, v, 1);
  dfs2(u, u);
  if (dist[1][u] % 2 == 1) ans--;
  cout << ans << endl;
  return 0;
}
