#include <bits/stdc++.h>
using namespace std;
int nmax = 100010;
vector<vector<int>> graph(nmax);
vector<int> usedu(nmax, -1);
vector<int> usedv(nmax, 1e9);
void dfs(vector<vector<int>> graph, int locate, int cnt) {
  cnt++;
  for (int i = 0; i < graph[locate].size(); i++) {
    if (usedv[graph[locate][i]] == 1e9) {
      usedv[graph[locate][i]] = cnt;
      dfs(graph, graph[locate][i], cnt);
    }
  }
}
void udfs(vector<vector<int>> graph, int locate, int cnt) {
  cnt++;
  for (int i = 0; i < graph[locate].size(); i++) {
    if (usedu[graph[locate][i]] == -1 && usedv[graph[locate][i]] >= cnt) {
      usedu[graph[locate][i]] = cnt;
      dfs(graph, graph[locate][i], cnt);
    }
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  if (u == v) {
    cout << 0 << endl;
    return 0;
  }
  usedu[u] = 0;
  usedv[v] = 0;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }
  dfs(graph, v, 0);
  udfs(graph, u, 0);
  for (int i = 0; i < n; i++) {
    if (usedu[i] == -1)
      usedu[i] = false;
    else
      usedu[i] = true;
  }
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    if (!usedu[i]) continue;
    maxi = max(maxi, usedv[i]);
  }
  cout << maxi - 1 << endl;
}
