#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using pii = std::pair<long long, long long>;
using namespace std;
long long n, u, v, a, b, tt[100005] = {0}, at[100005] = {0}, visited[100005],
                         parent[100005];
vector<long long> adj[100005];
class ABC148F {
 public:
  void solve(std::istream& in, std::ostream& out) {
    in >> n >> u >> v;
    u--;
    v--;
    if (n == 2) {
      out << "0\n";
      return;
    }
    for (long long i = (0); i < (n - 1); i++) {
      in >> a >> b;
      a--;
      b--;
      if (min(a, b) == min(u, v) && max(a, b) == max(u, v)) {
        out << "0\n";
        return;
      }
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    long long root = -1;
    for (long long i = (0); i < (n); i++) visited[i] = 0;
    for (long long i = (0); i < (n); i++)
      if (adj[i].size() > 1) {
        root = i;
        break;
      }
    assert(root != -1);
    set_par(root, -1);
    for (long long i = (0); i < (n); i++) visited[i] = 0;
    mark(u, 1, 0);
    for (long long i = (0); i < (n); i++) visited[i] = 0;
    mark(v, 0, 0);
    long long ans = 0;
    for (long long i = (0); i < (n); i++)
      if (adj[i].size() == 1) {
        long long x = parent[i];
        if ((at[x] - tt[x]) & 1)
          ans = max(ans, tt[x] - 1);
        else
          ans = max(ans, tt[x]);
      }
    out << ans << "\n";
  }
  void set_par(long long x, long long p) {
    if (visited[x]) return;
    visited[x] = 1;
    parent[x] = p;
    for (auto v : adj[x])
      if (!visited[x]) set_par(v, x);
  }
  void mark(long long x, long long is_t, long long t) {
    if (visited[x]) return;
    visited[x] = 1;
    if (is_t)
      tt[x] = t;
    else
      at[x] = t;
    for (auto v : adj[x])
      if (!visited[v]) mark(v, is_t, t + 1);
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ABC148F solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
