#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
int udis[200001];
int vdis[200001];
vector<int> ca[200001];
bool vis[200001];
queue<int> qu;
long long ans = 0;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a;
  int u, v;
  cin >> u >> v;
  for (int n = 0; n < a - 1; n++) {
    cin >> c >> d;
    ca[c].push_back(d);
    ca[d].push_back(c);
  }
  memset(vis, false, sizeof(vis));
  memset(udis, 1000000007, sizeof(udis));
  memset(vdis, 1000000007, sizeof(vdis));
  vdis[v] = 0;
  qu.push(v);
  vis[v] = true;
  while (!qu.empty()) {
    int x = qu.front();
    qu.pop();
    vis[x] = true;
    for (int n = 0; n < ca[x].size(); n++) {
      if (!vis[ca[x][n]] && vdis[x] + 1 < vdis[ca[x][n]]) {
        qu.push(ca[x][n]), vdis[ca[x][n]] = vdis[x] + 1;
      }
    }
  }
  memset(vis, false, sizeof(vis));
  udis[u] = 0;
  qu.push(u);
  vis[u] = true;
  while (!qu.empty()) {
    int x = qu.front();
    qu.pop();
    vis[x] = true;
    if (udis[x] <= vdis[x]) {
      ans = max(ans, (long long)udis[x]);
      if (udis[x] == vdis[x]) continue;
    }
    for (int n = 0; n < ca[x].size(); n++) {
      if (!vis[ca[x][n]] && udis[x] + 1 < udis[ca[x][n]]) {
        qu.push(ca[x][n]), udis[ca[x][n]] = udis[x] + 1;
      }
    }
  }
  cout << ans << '\n';
  return (0);
}
