#include <bits/stdc++.h>
using namespace std;
int N, u, t;
vector<int> adj_list[100100];
int d[100100];
int par[100100];
int dist[100100];
int a[100100];
void dfs(int v, int pv) {
  for (auto& nv : adj_list[v]) {
    if (nv == pv) {
      continue;
    }
    par[nv] = v;
    dfs(nv, v);
  }
}
int dfs2(int v, int pv) {
  int res = 0;
  for (auto& nv : adj_list[v]) {
    if (nv == pv || nv == a[v]) {
      continue;
    }
    par[nv] = v;
    res = max(res, dfs2(nv, v) + 1);
  }
  d[v] = res;
  return res;
}
void bfs() {
  queue<int> q;
  q.push(u - 1);
  for (int i = 0; i < N; i++) {
    dist[i] = -1;
  }
  dist[u - 1] = 0;
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto& nv : adj_list[v]) {
      if (dist[nv] == -1) {
        dist[nv] = dist[v] + 1;
        q.push(nv);
      }
    }
  }
}
int main() {
  cin >> N >> u >> t;
  for (int i = 0; i < N - 1; i++) {
    int Ai, Bi;
    cin >> Ai >> Bi;
    adj_list[Ai - 1].push_back(Bi - 1);
    adj_list[Bi - 1].push_back(Ai - 1);
  }
  dfs(u - 1, -1);
  vector<int> route = {t - 1};
  int now = t - 1;
  while (true) {
    now = par[now];
    route.push_back(now);
    if (now == u - 1) {
      break;
    }
  }
  bfs();
  int ans = dist[t - 1] - 1;
  for (int i = 0; i < N; i++) {
    a[i] = -1;
  }
  for (int i = 0; i < route.size(); i++) {
    if (i < route.size() - 1) {
      a[route[i + 1]] = route[i];
    }
  }
  dfs2(3, 4);
  for (int i = 0; i < route.size(); i++) {
    int d1 = dist[route[i]];
    int d2 = dist[t - 1] - d1;
    if (d1 > d2) {
      continue;
    }
    if (d1 == d2) {
      ans = max(ans, d2);
    }
    ans = max(ans, d1 + d[route[i]] + d2 - d1 - 1);
  }
  cout << ans << endl;
}
