#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long xx = 2e5;
const long long MOD = 1e9 + 7;
vector<long long> g[xx + 10];
vector<long long> dist, distT, par;
void dfs(long long c, long long p) {
  for (long long i : g[c]) {
    if (i != p) {
      par[i] = c;
      dist[i] = dist[c] + 1;
      dfs(i, c);
    }
  }
}
long long Max = 0, NMax = 0;
void dfslca(long long c, long long p) {
  for (long long i : g[c]) {
    if (i != p) {
      distT[i] = distT[c] + 1;
      if (distT[i] > Max) {
        Max = distT[i];
        NMax = i;
      }
      dfslca(i, c);
    }
  }
}
long long findroot(long long node) {
  long long cnt = 1;
  while (1) {
    long long p = par[node];
    if (dist[p] <= cnt) break;
    if (p == -1) break;
    node = p;
    cnt++;
  }
  return node;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, u, v;
  cin >> N >> u >> v;
  dist = distT = par = vector<long long>(N + 1, 0);
  for (long long i = 1; i < N; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  par[v] = -1;
  dfs(v, -1);
  long long lca = findroot(u);
  long long parentlca = par[lca];
  dfslca(lca, parentlca);
  NMax = max(NMax, dist[u]);
  cout << dist[NMax] - 1 << '\n';
}
