#include <bits/stdc++.h>
using namespace std;
int dist[100001];
void dfs(int v, int p, int d, const vector<vector<int>> &G) {
  dist[v] = d;
  for (auto &u : G[v]) {
    if (u == p) continue;
    dfs(u, v, d + 1, G);
  }
}
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  a--;
  b--;
  vector<vector<int>> G(n);
  vector<int> k(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    G[v].push_back(u);
    G[u].push_back(v);
    k[u]++;
    k[v]++;
  }
  if (n == 2) {
    cout << 0 << endl;
    return 0;
  }
  dfs(b, -1, 0, G);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (k[i] == 1) {
      ans = max(ans, dist[G[i][0]]);
    }
  }
  cout << ans << endl;
  return 0;
}
