#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e16;
void dfs(vector<vector<long long> > &g, long long v, long long u,
         vector<bool> &flag, vector<long long> &d) {
  flag[v] = true;
  for (auto next_v : g[v]) {
    if (flag[next_v]) continue;
    d[next_v] = d[v] + 1;
    dfs(g, next_v, u, flag, d);
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<long long> > G(n);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if (G[u].size() == 1 && G[u][0] == v) {
    cout << 0 << endl;
    return 0;
  }
  vector<bool> flagb(n, false), flagr(n, false);
  vector<long long> du(n, 0), dv(n, 0);
  dfs(G, v, u, flagb, dv);
  dfs(G, u, v, flagr, du);
  long long res = 0, index = -1;
  for (long long i = 0; i < n; i++)
    if (res < dv[i] && dv[i] > du[i]) {
      res = dv[i];
      index = i;
    }
  cout << dv[index] << endl;
}
