#include <bits/stdc++.h>
using namespace std;
long long n, U, V;
vector<vector<long long> > edges;
vector<long long> Adis, Tdis;
void dfs(long long u, long long d, vector<long long> &dis,
         vector<bool> visited) {
  visited[u] = 1;
  dis[u] = d;
  for (long long v : edges[u]) {
    if (!visited[v]) {
      dfs(v, d + 1, dis, visited);
    }
  }
}
void mymain() {
  cin >> n >> U >> V;
  U--;
  V--;
  edges.resize(n, vector<long long>());
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  Adis.resize(n, 0);
  Tdis.resize(n, 0);
  vector<bool> vis(n, false);
  dfs(U, 0, Tdis, vis);
  for (long long i = 0; i < n; i++) vis[i] = false;
  dfs(V, 0, Adis, vis);
  bool ok = true;
  set<long long> s1, s2;
  for (long long i : edges[U]) s1.insert(i);
  for (long long i : edges[V]) s2.insert(i);
  if (s1 == s2) ok = false;
  if (!ok) {
    cout << 1 << '\n';
    return;
  }
  long long ans = INT_MIN;
  for (long long i = 0; i < n; i++) {
    if (Tdis[i] < Adis[i])
      ans = max(ans, Adis[i] - 1);
    else if (Tdis[i] == Adis[i])
      ans = max(ans, Adis[i]);
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t = 1;
  for (long long tt = 0; tt < t; tt++) {
    mymain();
  }
  return 0;
}
