#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
using ll = long long;
using P = pair<long long, long long>;
vector<long long> ki[110000];
void dfs(long long now, long long last, vector<long long>& dist) {
  for (auto next : ki[now]) {
    if (next == last) continue;
    dist[next] = dist[now] + 1;
    dfs(next, now, dist);
  }
}
signed main() {
  long long n, tak, aok;
  cin >> n >> tak >> aok;
  tak--;
  aok--;
  for (long long i = 0; i < (n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    ki[a].push_back(b);
    ki[b].push_back(a);
  }
  vector<long long> takahashi(n), aoki(n);
  dfs(tak, -1, takahashi);
  dfs(aok, -1, aoki);
  vector<long long> kouho;
  for (long long i = 0; i < (n); i++) {
    if (takahashi[i] < aoki[i]) {
      kouho.push_back(i);
    }
  }
  long long ret = 0;
  long long tmp = 0;
  for (auto i : kouho) {
    if (tmp <= takahashi[i]) {
      ret = i;
    }
    tmp = max(tmp, takahashi[i]);
  }
  cout << aoki[ret] - 1 << endl;
  return 0;
}
