#include <bits/stdc++.h>
using namespace std;
int N, u, v;
vector<vector<int>> edge;
int trace[200000 + 100];
int dis[200000 + 100];
vector<int> kerirojou;
bool saitanro[200000 + 100];
void dfs(int pos, int bef) {
  for (int i = 0; i < edge[pos].size(); i++) {
    int nxt = edge[pos][i];
    if (nxt == bef) continue;
    dis[nxt] = dis[pos] + 1;
    trace[nxt] = pos;
    dfs(nxt, pos);
  }
}
int dfs2(int pos, int bef, int d) {
  int ret = 0;
  for (int i = 0; i < edge[pos].size(); i++) {
    int nxt = edge[pos][i];
    if (nxt == bef) continue;
    if (saitanro[nxt]) continue;
    ret = max(ret, dfs2(nxt, pos, d + 1));
  }
  if (ret == 0) return d;
  return ret;
}
int main() {
  cin >> N >> u >> v;
  u--, v--;
  edge.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for (int i = 0; i < N; i++) trace[i] = -1;
  dfs(u, -1);
  int npos = v;
  saitanro[v] = true;
  saitanro[u] = true;
  while (true) {
    if (trace[npos] == -1) break;
    npos = trace[npos];
    if (trace[npos] == -1) break;
    saitanro[npos] = true;
    kerirojou.push_back(npos);
  }
  int ans = dis[v] - 1;
  for (int i = 0; i < kerirojou.size(); i++) {
    if (kerirojou[i] == u) continue;
    if (dis[kerirojou[i]] * 2 < dis[v]) {
      int tmp = dfs2(kerirojou[i], -1, 0);
      ans = max(ans, dis[kerirojou[i]] + tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
