#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, bool>;
using graph = map<int, vector<int>>;
int dfs_a(graph &G, vector<bool> &seen_a, vector<P> &a, int v, bool f, int d,
          int u, int &tm, int &fm) {
  d++;
  seen_a[v] = true;
  if (v == u) f = true;
  for (auto nv : G[v]) {
    if (seen_a[nv]) continue;
    dfs_a(G, seen_a, a, nv, f, d, u, tm, fm);
  }
  if (f) {
    a[v].first = d;
    a[v].second = true;
    tm = max(tm, d);
  } else {
    a[v].first = d;
    a[v].second = false;
    fm = max(fm, d);
  }
  if (v == u) f = false;
  d--;
  return 0;
}
int dfs_b(graph &G, vector<bool> &seen_b, vector<int> &b, int v, int d) {
  d++;
  seen_b[v] = true;
  for (auto nv : G[v]) {
    if (seen_b[nv]) continue;
    dfs_b(G, seen_b, b, nv, d);
  }
  b[v] = d;
  d--;
  return 0;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  graph G;
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<P> a(n + 1);
  vector<bool> seen_a(n + 1, false);
  bool f = false;
  int tm = 0;
  int fm = 0;
  dfs_a(G, seen_a, a, v, f, 0, u, tm, fm);
  if (tm >= fm) {
    cout << tm - 2 << endl;
  } else {
    vector<int> b(n + 1, 0);
    vector<bool> seen_b(n + 1, false);
    dfs_b(G, seen_b, b, u, 0);
    bool flag = false;
    for (int i = 1; i < (n + 1); ++i) {
      if (a[i].second == false && a[i].first == fm) {
        if (fm > b[i]) {
          flag = true;
        }
      }
    }
    if (flag) {
      cout << fm - 2 << endl;
    } else {
      cout << tm - 2 << endl;
    }
  }
  return 0;
}
