#include <bits/stdc++.h>
using namespace std;
int n, u, v, t, a;
vector<int> T[100001];
bool visited[100001];
int dis[100001] = {0};
bool leaf[100001] = {0};
bool childOfT[100001] = {0};
void dfs(int s, int d, int childOff) {
  visited[s] = 1;
  dis[s] = d;
  if (s == t) {
    childOff = 1;
  }
  childOfT[s] = childOff;
  int count = 0;
  for (auto x : T[s]) {
    if (!visited[x]) {
      dfs(x, d + 1, childOff);
      count++;
    }
  }
  if (count == 0) leaf[s] = 1;
}
int main() {
  cin >> n >> t >> a;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    T[u].push_back(v);
    T[v].push_back(u);
  }
  dfs(a, 0, 0);
  int at = dis[t];
  int dima = INT_MAX;
  for (int i = 1; i <= n; i++) {
    if (leaf[i] and childOfT[i]) {
      dima = min(dima, dis[i]);
    }
  }
  cout << (dima - at) + (at - 1) << "\n";
  return 0;
}
