#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}
template <typename T>
void print_array(const T &ary, int size) {
  for (int i = (0); i < (size); ++i) {
    cout << ary[i] << " ";
  }
  cout << endl;
}
const int MOD = 1e9 + 7;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
vector<vector<int> > g;
vector<int> A;
int ans = -1;
void dfs_aoki(int v, int acc, int pre) {
  A[v] = acc;
  for (int u : g[v]) {
    if (u == pre) continue;
    dfs_aoki(u, acc + 1, v);
  }
}
void dfs_taka(int v, int acc, int pre, int rev) {
  ;
  ;
  ;
  if (A[v] <= acc) {
    chmax(ans, A[v]);
    return;
  }
  if (rev) {
    dfs_taka(pre, acc + 1, v, 0);
  } else {
    for (int u : g[v]) {
      if (u == pre) {
        if (((int)(g[v]).size()) != 1) continue;
        dfs_taka(u, acc + 1, v, 1);
      } else {
        dfs_taka(u, acc + 1, v, 0);
      }
    }
  }
}
signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(12);
  int N;
  cin >> N;
  g.resize(N);
  A.resize(N);
  int S, T;
  cin >> S >> T;
  S--;
  T--;
  for (int i = (0); i < (N - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  dfs_aoki(T, 0, -1);
  dfs_taka(S, 0, -1, 0);
  cout << ans << endl;
}
