#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long add(long long a, long long b, long long m) {
  return (((a % m + b % m) % m + m) % m);
}
inline long long mul(long long a, long long b, long long m) {
  return (((a % m * b % m) % m + m) % m);
}
const double EPS = 1e-6;
const long long MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
  out << '[' << p.first << ", " << p.second << ']';
  return out;
}
template <template <typename, typename...> class ContainerType,
          typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c) {
  cout << "{ ";
  for (const auto &v : c) cout << v << ' ';
  cout << '}' << '\n';
}
const int N = 1e5 + 5;
bool pres[N];
int deg[N], par[N];
void dfs1(int ii, int pp, vector<vector<int> > &g) {
  par[ii] = pp;
  bool ans = false;
  for (auto jj : g[ii])
    if (jj != pp) dfs1(jj, ii, g);
  for (auto jj : g[ii])
    if (jj != pp) pres[ii] |= pres[jj];
  return;
}
void dfs2(int ii, int pp, vector<vector<int> > &g, int h, int &mx) {
  mx = max(mx, h);
  for (auto jj : g[ii])
    if (jj != pp) dfs2(jj, ii, g, h + 1, mx);
  return;
}
void solve() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<vector<int> > g(n + 1, vector<int>());
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  pres[t] = true;
  dfs1(a, -1, g);
  if (deg[t] == 1 && par[t] == a) {
    cout << 0 << '\n';
    return;
  }
  int mx = -1;
  for (auto jj : g[a])
    if (pres[jj]) {
      dfs2(jj, a, g, 0, mx);
      cout << mx << '\n';
      return;
    }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  clock_t start, stop;
  int t = 1;
  for (int tc = 1; tc < t + 1; tc++) solve();
  return 0;
}
