#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e14;
const long long ZERO = 0;
const long long MOD = 1000000007;
const double PI = 3.1415926535897;
struct edge {
  long long to, cost;
};
typedef pair<long long, long long> P;
long long V;
vector<edge> G[100010];
long long d[100010];
void dijkstra(long long s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    long long v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (long long i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
signed main() {
  long long u, v;
  cin >> V >> u >> v;
  u--;
  v--;
  for (long long i = 0; i < V - 1; i++) {
    long long A, B;
    cin >> A >> B;
    A--;
    B--;
    G[A].push_back(edge{B, 1});
    G[B].push_back(edge{A, 1});
  }
  dijkstra(u);
  vector<long long> U(V);
  for (long long i = 0; i < V; i++) {
    U.at(i) = d[i];
  }
  dijkstra(v);
  vector<long long> vv(V);
  for (long long i = 0; i < V; i++) {
    vv.at(i) = d[i];
  }
  long long ret = 0;
  for (long long i = 0; i < V; i++) {
    if (vv.at(i) + U.at(i) == vv.at(u)) {
      ret = max(ret, vv.at(u) / 2);
    } else if (vv.at(i) >= U.at(i)) {
      ret = max(ret, vv.at(i) - 1);
    }
  }
  cout << ret << endl;
}
