#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G(100100);
int d[2][100100];
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < (n - 1); ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  queue<int> q;
  q.push(u);
  for (int i = 0; i < (2); ++i)
    for (int j = 0; j < (100100); ++j) d[i][j] = -1;
  d[0][u] = 0;
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (auto b : G[a]) {
      if (d[0][b] == -1) {
        d[0][b] = d[0][a] + 1;
        q.push(b);
      }
    }
  }
  d[1][v] = 0;
  q.push(v);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (auto b : G[a]) {
      if (d[1][b] == -1) {
        d[1][b] = d[1][a] + 1;
        q.push(b);
      }
    }
  }
  int mx = 1;
  for (int i = 0; i < (n); ++i) {
    if (d[0][i] < d[1][i]) (mx = max(mx, d[0][i]));
  }
  if ((int)(G[u]).size() == 1 && G[u][0] == v) mx = 0;
  cout << mx << endl;
  return 0;
}
