#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
vector<int> seen;
int cnt = 0;
int dfs(const vector<vector<int>> &G, int v) {
  for (auto next_v : G[v]) {
    if (seen[next_v] != -1) continue;
    seen[next_v] = seen[v] + 1;
    dfs(G, next_v);
  }
}
int sch(const vector<vector<int>> &G, int v) {
  cnt++;
  if (cnt > seen[v]) {
    int ans = min(seen[v], cnt - 1);
    cout << ans << endl;
    return 0;
  }
  int m_dis = 0;
  int next;
  for (auto next_v : G[v]) {
    if (m_dis <= seen[next_v]) {
      m_dis = seen[next_v];
      next = next_v;
    }
  }
  sch(G, next);
}
int main(void) {
  int N;
  int u, v;
  cin >> N;
  cin >> u >> v;
  u--;
  v--;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  seen.assign(N, -1);
  seen[v] = 0;
  dfs(G, v);
  sch(G, u);
}
