#include <bits/stdc++.h>
using namespace std;
int n, v, u, ai, bi;
vector<int> g[100001];
int dv[100001], du[100001];
queue<pair<int, int> > q;
int main() {
  cin >> n >> v >> u;
  --v, --u;
  for (int i = (0); i < (n - 1); ++i) {
    cin >> ai >> bi;
    --ai;
    --bi;
    g[ai].emplace_back(bi);
    g[bi].emplace_back(ai);
  }
  memset(dv, -1, sizeof(dv));
  memset(du, -1, sizeof(du));
  du[u] = 0;
  q.push(pair<int, int>(u, 0));
  while (!q.empty()) {
    pair<int, int> c = q.front();
    q.pop();
    for (int nu : g[c.first])
      if (du[nu] == -1) {
        q.push(pair<int, int>(nu, c.second + 1));
        du[nu] = c.second + 1;
      }
  }
  dv[v] = 0;
  q.push(pair<int, int>(v, 0));
  while (!q.empty()) {
    pair<int, int> c = q.front();
    q.pop();
    for (int nv : g[c.first])
      if (dv[nv] == -1 && c.second + 1 < du[nv]) {
        q.push(pair<int, int>(nv, c.second + 1));
        dv[nv] = c.second + 1;
      }
  }
  int mx = 0;
  for (int i = (0); i < (n); ++i)
    if (dv[i] < du[i]) mx = max(mx, du[i] - 1);
  cout << mx << endl;
  return 0;
}
