#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  int cost;
};
using P = pair<int, int>;
int V;
vector<edge> G[100000];
int d[100000];
int dd[100000];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, 1e+9);
  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));
      }
    }
  }
}
void dijkstra2(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(dd, dd + V, 1e+9);
  dd[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dd[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (dd[e.to] > dd[v] + e.cost) {
        dd[e.to] = dd[v] + e.cost;
        que.push(P(dd[e.to], e.to));
      }
    }
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  V = N + 1;
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edge e = {a, 1};
    edge e2 = {b, 1};
    G[a].push_back(e2);
    G[b].push_back(e);
  }
  if (u == v) {
    cout << 0 << endl;
    return 0;
  }
  edge e = {v, 0};
  edge e2 = {u, 0};
  G[0].push_back(e);
  G[0].push_back(e2);
  dijkstra(v);
  dijkstra2(u);
  int maximum = 0;
  for (int i = 1; i < N + 1; ++i) {
    if (d[i] != 1e+9) {
      if (d[i] > dd[i]) {
        if (maximum < d[i]) {
          maximum = d[i];
        }
      }
    }
  }
  cout << maximum - 1 << endl;
}
