#include <bits/stdc++.h>
using namespace std;
int BFS(int origem, int destino, vector<vector<int> > &graph, int n) {
  queue<int> fila;
  fila.push(origem);
  vector<int> dist(n, int(1e9));
  dist[origem] = 0;
  int maxi = 0;
  while (!fila.empty()) {
    int vertex = fila.front();
    fila.pop();
    maxi = max(dist[vertex], maxi);
    for (int i = 0; i < graph[vertex].size(); i++) {
      int adj = graph[vertex][i];
      if (dist[adj] > dist[vertex] + 1)
        dist[adj] = dist[vertex] + 1, fila.push(adj);
    }
  }
  return maxi - 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  a--, b--;
  vector<vector<int> > graph(n);
  for (int i = 0; i < n - 1; i++) {
    int X, Y;
    cin >> X >> Y;
    X--, Y--;
    graph[X].push_back(Y);
    graph[Y].push_back(X);
  }
  cout << max(BFS(a, b, graph, n), BFS(b, a, graph, n)) << endl;
  return 0;
}
