#include <bits/stdc++.h>
template <class T>
inline T chmax(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T chmin(T& a, const T b) {
  return a = (a > b) ? b : a;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
using namespace std;
vector<vector<pair<ll, ll>>> graph;
vector<ll> dijkstra(ll i, ll n, vector<vector<pair<ll, ll>>> graph) {
  vector<ll> d(n, INF);
  d[i] = 0;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<ll, ll> p = q.top();
    q.pop();
    ll v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<ll, ll>(d[x.first], x.first));
      }
    }
  }
  return d;
}
signed main() {
  ll N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  graph = vector<vector<pair<ll, ll>>>(N);
  ll a, b;
  for (ll i = 0; i < ll(N - 1); ++i) {
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(make_pair(b, 1));
    graph[b].push_back(make_pair(a, 1));
  }
  ll flag = 0;
  for (ll i = 0; i < ll(graph[u].size()); ++i) {
    if (graph[u][i].first != v) flag = 1;
  }
  if (!flag) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> dist1 = dijkstra(u, N, graph);
  vector<ll> dist2 = dijkstra(v, N, graph);
  ll ans = 0;
  for (ll i = 0; i < ll(N); ++i) {
    if (dist1[i] < dist2[i]) chmax(ans, dist1[i]);
  }
  if (ans == 0) ans++;
  cout << ans << endl;
  return 0;
}
