#include <bits/stdc++.h>
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
using long long int = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
class Solve {
 public:
  Int N, U, V;
  vector<vector<Int>> tree;
  vector<Int> tdist, adist;
  void tdfs(int v, int d = 0, int p = -1) {
    if (V == v) return;
    tdist[v] = d;
    for (auto e : tree[v]) {
      if (e != p) {
        tdfs(e, d + 1, v);
      }
    }
  }
  void adfs(int v, int d = 0, int p = -1) {
    adist[v] = d;
    for (auto e : tree[v]) {
      if (e != p) {
        adfs(e, d + 1, v);
      }
    }
  }
  void solve() {
    cin >> N >> U >> V;
    tree.resize(N);
    tdist.resize(N, -1);
    adist.resize(N);
    U--, V--;
    for (int i = 0; i + 1 < N; ++i) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      tree[a].push_back(b);
      tree[b].push_back(a);
    }
    tdfs(U);
    adfs(V);
    Int best_key = -1;
    Int best_value = -1;
    for (int i = 0; i < N; ++i) {
      if (tree[i].size() == 1) {
        if (best_value < tdist[i] && tdist[i] < adist[i] && tdist[i] != -1) {
          best_value = tdist[i];
          best_key = i;
        }
      }
    }
    Int ans = adist[best_key] - 1;
    cout << ans << endl;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  Solve().solve();
  return 0;
}
