#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
const long long INF = 999999999;
ll N;
vector<ll> edge[100010];
bool used[100010];
ll d1[100010], d2[100010];
void bfs(ll u, ll (&d)[100010], vector<ll>& leaf) {
  queue<ll> que;
  fill(used, used + N + 10, false);
  used[u] = true;
  d[u] = 0;
  que.push(u);
  while (!que.empty()) {
    ll s = que.front();
    que.pop();
    for (int i = 0; i < edge[s].size(); i++) {
      ll t = edge[s][i];
      if (!used[t]) {
        used[t] = true;
        d[t] = d[s] + 1;
        que.push(t);
      }
    }
    if (edge[s].size() <= 1) leaf.push_back(s);
  }
}
int main() {
  ll u, v;
  cin >> N >> u >> v;
  for (int i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vector<ll> leaf;
  bfs(u, d1, leaf);
  bfs(v, d2, leaf);
  ll nige, dmax = -1;
  for (int i = 0; i < leaf.size(); i++) {
    ll s = leaf[i];
    if (d1[s] < d2[s] && dmax < d1[s]) {
      dmax = d1[s];
      nige = s;
    }
  }
  cout << d2[nige] - 1 << endl;
}
