#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 123;
int dist[N];
vector<int> g[N];
int res = 0;
void dfs(int v, int pr = -1) {
  for (auto to : g[v]) {
    if (to != pr) {
      dist[to] = dist[v] + 1;
      dfs(to, v);
    }
  }
}
void dfs2(int v, int d) {
  if (d >= dist[v]) return;
  res = max(res, dist[v] - 1);
  for (auto to : g[v]) dfs(to, d + 1);
}
int main() {
  cerr << "Ready\n";
  int n, s, f;
  cin >> n >> s >> f;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  dfs(f);
  dfs2(s, 0);
  cout << res;
  cerr << '\n';
}
