#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long MOD = 1e9 + 7;
vector<long long> adj[N];
long long dist[2][N];
bool vis[N];
void dfs(long long u, long long d, long long idx) {
  vis[u] = 1;
  dist[idx][u] = d;
  for (auto &v : adj[u])
    if (!vis[v]) dfs(v, d + 1, idx);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, u, v;
  cin >> n >> u >> v;
  for (long long i = 0, a, b; i < n - 1; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(u, 0, 0);
  memset(vis, 0, sizeof(vis));
  dfs(v, 0, 1);
  long long big = 0, same = n;
  bool flg = 0;
  for (long long i = 1; i <= n; i++)
    if (dist[0][i] < dist[1][i]) big = max(big, dist[0][i]);
  for (long long i = 1; i <= n; i++)
    if (dist[0][i] == dist[1][i]) same = min(same, dist[0][i]), flg = 1;
  if (!flg) return cout << big, 0;
  cout << max(big, same);
}
