#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long, long long>;
using ll = long long;
long long n, l;
vector<long long> adj[100010];
long long timer;
vector<long long> tin, tout;
vector<vector<long long>> up;
void dfs(long long v, long long p) {
  tin[v] = ++timer;
  up[v][0] = p;
  for (long long i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (long long u : adj[v]) {
    if (u != p) dfs(u, v);
  }
  tout[v] = ++timer;
}
bool is_ancestor(long long u, long long v) {
  return tin[u] <= tin[v] && tout[u] >= tout[v];
}
long long lca(long long u, long long v) {
  if (is_ancestor(u, v)) return u;
  if (is_ancestor(v, u)) return v;
  for (long long i = l; i >= 0; --i) {
    if (!is_ancestor(up[u][i], v)) u = up[u][i];
  }
  return up[u][0];
}
void init() {
  tin.resize(n + 1);
  tout.resize(n + 1);
  timer = 0;
  l = ceil(log2(n + 1));
  up.assign(n + 1, vector<long long>(l + 1));
  dfs(n, n);
}
long long dist[2][100010];
void calcd(long long w, long long k) {
  vector<bool> visited(n + 1, false);
  queue<pair<long long, long long>> q;
  q.push({w, 0});
  visited[w] = true;
  while (not q.empty()) {
    long long u = q.front().first;
    long long d = q.front().second;
    q.pop();
    dist[k][u] = d;
    for (auto v : adj[u]) {
      if (visited[v]) continue;
      visited[v] = true;
      q.push({v, d + 1});
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  long long t, a;
  cin >> n >> t >> a;
  for (long long i = 0; i < n - 1; ++i) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  init();
  calcd(t, 0);
  calcd(a, 1);
  long long lc = lca(t, a);
  long long tl = dist[0][lc];
  long long al = dist[1][lc];
  long long ans = 0;
  ans = dist[1][t];
  if (tl < al) {
    for (long long i = 1; i <= n; ++i) {
      if (dist[1][i] <= dist[0][i]) continue;
      if (dist[1][i] > ans) ans = dist[1][i];
    }
  }
  cout << ans - 1 << endl;
}
