#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  long long to, cost;
};
struct graph {
  long long V;
  vector<vector<edge>> G;
  vector<long long> d;
  graph(long long n) { init(n); }
  void init(long long n) {
    V = n;
    G.resize(V);
    d.resize(V);
    for (int i = 0; i < V; i++) {
      d[i] = 2e9;
    }
  }
  void add_edge(long long s, long long t, long long cost) {
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }
  void dijkstra(long long s) {
    for (int i = 0; i < V; i++) {
      d[i] = 2e9;
    }
    d[s] = 0;
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        que;
    que.push(pair<long long, long long>(0, s));
    while (!que.empty()) {
      pair<long long, long long> p = que.top();
      que.pop();
      long long v = p.second;
      if (d[v] < p.first) continue;
      for (auto e : G[v]) {
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(pair<long long, long long>(d[e.to], e.to));
        }
      }
    }
  }
};
int main() {
  long long N, t, a;
  cin >> N >> t >> a;
  t--;
  a--;
  vector<pair<long long, long long>> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i].first >> A[i].second;
    A[i].first--;
    A[i].second--;
  }
  graph g(N);
  for (int i = 0; i < N - 1; i++) {
    g.add_edge(A[i].first, A[i].second, 1);
    g.add_edge(A[i].second, A[i].first, 1);
  }
  g.dijkstra(t);
  vector<long long> taka = g.d;
  g.dijkstra(a);
  vector<long long> aoki = g.d;
  long long MAX = -1;
  for (int i = 0; i < N; i++) {
    if (taka[i] < aoki[i]) {
      MAX = max(MAX, taka[i]);
    }
  }
  long long MAX2 = -1;
  for (int i = 0; i < N; i++) {
    if (taka[i] == MAX && taka[i] < aoki[i]) {
      MAX2 = max(MAX2, aoki[i]);
    }
  }
  cout << MAX2 - 1 << endl;
}
