#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MOD_9 = 998244353;
struct edge {
  int to;
  int cost;
};
typedef pair<int, int> P;
vector<edge> tree[100000];
int d[2][100000];
void dijkstra(int s, int x) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d[x], d[x] + 100000, 1e18);
  d[x][s] = 0;
  que.push(P(d[x][s], s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[x][v] < p.first) {
      continue;
    }
    for (int i = 0; i < tree[v].size(); i++) {
      edge e = tree[v][i];
      if (d[x][e.to] > d[x][v] + e.cost) {
        d[x][e.to] = d[x][v] + e.cost;
        que.push(P(d[x][e.to], e.to));
      }
    }
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  for (int((i)) = (0); ((i)) < ((N - 1)); (i)++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge e = {b, 1};
    tree[a].push_back(e);
    e = {a, 1};
    tree[b].push_back(e);
  }
  int ans;
  dijkstra(u, 0);
  dijkstra(v, 1);
  ans = d[1][u];
  ans -= 1;
  for (int((i)) = (0); ((i)) < ((N)); (i)++) {
    if (d[1][i] > d[0][i])
      ans = max(ans, d[1][i] - 1);
    else if (d[1][i] == d[0][i])
      ans = max(ans, d[1][i]);
  }
  cout << ans;
}
