#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, s, q;
vector<int> g[N];
int up[N], down[N];
int par[N];
void dfs(int u, int p, int d) {
  par[u] = p;
  up[u] = d;
  down[u] = 0;
  for (int v : g[u]) {
    if (v != p) {
      dfs(v, u, d + 1);
      down[u] = max(down[u], down[v] + 1);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q >> s;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (auto h : g[q]) {
    if (h == s) {
      printf("0");
      return 0;
    }
  }
  dfs(s, -1, 0);
  int u = q;
  int ans = 0;
  while (1) {
    if (up[u] <= up[s] - up[u]) break;
    ans = max(ans, (up[u] + down[u]) << 1);
    u = par[u];
  }
  cout << (ans / 2) - 1 << '\n';
}
