#include <bits/stdc++.h>
using namespace std;
void desperate_optimization(int precision) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
const int N = 1e5;
vector<int> lst[N + 5];
int dist[N + 5];
void dfs(int cur, int p, int m) {
  dist[cur] = m;
  for (int i = 0; i < lst[cur].size(); i++) {
    int to = lst[cur][i];
    if (p == to) continue;
    dfs(to, cur, m + 1);
  }
}
int res = 0;
void dfs2(int cur, int p, int m) {
  for (int i = 0; i < lst[cur].size(); i++) {
    int to = lst[cur][i];
    if (to == p) continue;
    if (m + 1 >= dist[to])
      res = max(res, dist[to]);
    else
      res = max(res, dist[to] - 1);
    if (m + 1 < dist[to]) dfs2(to, cur, m + 1);
  }
}
void hora(int tc) {
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    lst[a].push_back(b);
    lst[b].push_back(a);
  }
  dfs(v, v, 0);
  dfs2(u, u, 0);
  cout << res << '\n';
}
int main() {
  desperate_optimization(10);
  int ntc = 1;
  for (int tc = 1; tc <= ntc; tc++) hora(tc);
  return 0;
}
