#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
vector<int> G[N];
int n, u, v, dis[2][N];
bool vis[N];
void bfs(int u, int type) {
  queue<int> q;
  q.push(u);
  memset(vis + 1, 0, n * sizeof(bool));
  vis[u] = 1;
  dis[type][u] = 0;
  while ((int)q.size()) {
    int cur = q.front();
    q.pop();
    for (int v : G[cur]) {
      if (vis[v]) continue;
      vis[v] = 1;
      dis[type][v] = dis[type][cur] + 1;
      q.push(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bfs(u, 0);
  bfs(v, 1);
  if ((int)G[u].size() == 1 && dis[1][G[u][0]] <= 1)
    return cout << dis[1][G[u][0]], 0;
  int maxn = 0;
  for (int i = 1; i <= n; i++) {
    if (i == u || i == v) continue;
    if (dis[0][i] < dis[1][i] && dis[1][i] > maxn) maxn = dis[1][i];
  }
  cout << maxn - 1;
  return 0;
}
