#include <bits/stdc++.h>
using namespace std;
long long n, u, v;
vector<long long> G[100005];
long long distT[100005], distA[100005];
bool used[100005];
void dfs(int v, int p, int d, long long dist[]) {
  dist[v] = d;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == p) continue;
    dfs(G[v][i], v, d + 1, dist);
  }
}
void dfs2(int v, int p) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == p) continue;
    if (distA[G[v][i]] <= distT[G[v][i]]) continue;
    dfs2(G[v][i], v);
  }
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> u >> v;
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(u, -1, 0, distT);
  dfs(v, -1, 0, distA);
  dfs2(u, -1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (used[i]) ans = max(ans, distA[i]);
  }
  cout << ans - 1 << endl;
  return 0;
}
