#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
struct edge {
  int to;
  int cost;
};
int V;
vector<edge> G[100005];
int d[100005];
int d2[100005];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, 1001001001);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int 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));
      }
    }
  }
}
int main() {
  int u, v;
  cin >> V >> u >> v;
  u--;
  v--;
  for (int i = 0; i < V - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge e = {b, 1};
    edge e2 = {a, 1};
    G[a].push_back(e);
    G[b].push_back(e2);
  }
  dijkstra(u);
  swap(d, d2);
  dijkstra(v);
  int ans = 0;
  for (int i = 0; i < V; i++) {
    if (d[i] < d2[i]) {
      ans = max(ans, d2[i]);
    }
  }
  ans--;
  cout << ans << endl;
  return 0;
}
