#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<vector<int> > graph(n);
  for (int _ = (0); _ < (n - 1); ++_) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }
  vector<int> peko(n, -1);
  peko[v] = 0;
  queue<int> kama;
  kama.emplace(v);
  while (!kama.empty()) {
    int now = kama.front();
    kama.pop();
    for (int e : graph[now]) {
      if (peko[e] == -1) {
        peko[e] = peko[now] + 1;
        kama.emplace(e);
      }
    }
  }
  int ans = 0;
  queue<pair<int, int> > milk;
  milk.emplace(0, u);
  while (!milk.empty()) {
    int cnt = milk.front().first, ver = milk.front().second;
    milk.pop();
    for (int e : graph[ver]) {
      if (cnt + 1 < peko[e]) {
        milk.emplace(cnt + 1, e);
      } else {
        ans = max(ans, peko[e]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
