#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

// #define ANS  //for answer
#define CMP  //for compe
#ifdef CMP
using namespace std;
#else
#endif

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x, (x)
#define ncv(x) #x, ":", (x)
#define ncvc(x) #x, ":", (x), ","
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) { pPRINT(std::cout, t...); }
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  REP(i, size)
  PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  REP(i, size)
  PRINTl(i, ":", t[i]);
}
#ifndef DBG
#define DEBUG(...)
void init() {}
#else
#define DEBUG(...)                                                     \
  {                                                                    \
    PRINT("##DEBUG##", "file :", __FILE__, ", line :", __LINE__, "["); \
    PRINT(__VA_ARGS__);                                                \
    PRINTl("]");                                                       \
  }
void init() {
  DEBUG("INIT");
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char* argv[]) {
  DEBUG("MAIN");
  init();
  solve();

  return 0;
}

bool dfs_vtou(vector<vector<ll>>& tree, vector<ll>& path, ll parent, ll u, ll now, ll depth) {
  ll d = depth;
  for (ll i : tree[now]) {
    if (i == parent) continue;
    if (i == u) {
      path.push_back(i);
      path.push_back(now);
      return true;
    }
    if (dfs_vtou(tree, path, now, u, i, depth + 1)) {
      path.push_back(now);
      return true;
    }
  }
  return false;
}

ll dfs(vector<vector<ll>>& tree, ll parent, ll now, ll depth) {
  ll d = depth;
  for (auto i : tree[now]) {
    if (i == parent) continue;
    d = max(d, dfs(tree, now, i, depth + 1));
  }
  return d;
}

ll ans(vector<vector<ll>>& tree, ll u, ll v) {
  vector<ll> uvpath;
  DEBUG(ncv(u), ncv(v));
  dfs_vtou(tree, uvpath, -1, u, v, 0);
  DEBUG("path is solve");
  DEBUG("tree");
  REP(i, tree.size()) {
    // PRINT(ncv(i), ":::");
    // PRINTa(&tree[i][0], tree[i].size());
  }
  DEBUG("path");
  // PRINTa(&uvpath[0], uvpath.size());
  // return uvpath.size();
  ll pathhalfroot = uvpath[uvpath.size() / 2];
  ll d = dfs(tree, pathhalfroot, uvpath[uvpath.size() / 2 - 1], 0);
  DEBUG(ncv(uvpath.size()), ncv(d));
  return d + (uvpath.size() - 1) / 2;
}

void solve() {
  DEBUG("SOLVE START");

  ll n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  ll a[n - 1], b[n - 1];
  REP(i, n - 1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  // DEBUG();
  vector<vector<ll>> t(n, vector<ll>());
  REP(i, n - 1) {
    t[a[i]].push_back(b[i]);
    t[b[i]].push_back(a[i]);
  }
  PRINT(ans(t, u, v));

  return;
}

Measured memory_bytes: 14452