#include <bits/stdc++.h>
using namespace std;
int N, u, v;
vector<int> G[100005];
void dfs(int x, int px, int d, vector<int>& dist) {
  if (dist[x] != -1) return;
  dist[x] = d;
  for (int i = (0); i < (int)(G[x].size()); i++) {
    if (G[x][i] == px) continue;
    dfs(G[x][i], x, d + 1, dist);
  }
}
void dfs2(int x, int px, int d, vector<int>& dist, vector<int>& dist2) {
  if (dist[x] <= d) return;
  if (dist2[x] != -1) return;
  dist2[x] = d;
  for (int i = (0); i < (int)(G[x].size()); i++) {
    if (G[x][i] == px) continue;
    dfs2(G[x][i], x, d + 1, dist, dist2);
  }
}
int main() {
  cin >> N >> u >> v;
  u--;
  v--;
  for (int i = (0); i < (int)(N - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> taka(N, -1), ao(N, -1);
  dfs(v, -1, 0, ao);
  dfs2(u, -1, 0, ao, taka);
  int mx = -1;
  for (int i = (0); i < (int)(N); i++) {
    if (taka[i] == -1) continue;
    if (ao[i] > taka[i]) {
      if (mx < ao[i]) {
        mx = taka[i];
      }
    }
  }
  cout << mx << endl;
  return 0;
}
