#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char c) { return string(1, c); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (int i = int(N) - 1; i >= 0; --i) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
void GetDistAoki(vector<vector<int>>& adj, int start, vector<int>& dist) {
  int N = adj.size();
  dist[start] = 0;
  queue<int> q;
  q.push(start);
  int d = 1;
  while (q.size()) {
    for (int iq = q.size() - 1; iq >= 0; --iq) {
      int from = q.front();
      q.pop();
      for (auto to : adj[from]) {
        if (dist[to] == -1) {
          dist[to] = d;
          q.emplace(to);
        }
      }
    }
    ++d;
  }
}
void DFS(int from, vector<vector<int>>& adj, vector<int>& dist_aoki, ll steps,
         ll& ans, vector<array<int, 2>>& max_steps) {
  if (max_steps[from][steps & 1] > steps) return;
  max_steps[from][steps & 1] = steps;
  ans = max(ans, steps);
  for (auto to : adj[from]) {
    if (steps + 1 < dist_aoki[to]) {
      DFS(to, adj, dist_aoki, steps + 1, ans, max_steps);
    } else if (steps + 1 == dist_aoki[to]) {
      ans = max(ans, steps + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll N, U, A;
  cin >> N >> U >> A;
  --U, --A;
  vector<vector<int>> adj(N);
  for (int i = 0; i < N - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  if (U == A) {
    cout << 0 << '\n';
    return 0;
  }
  vector<int> dist_Aoki(N, -1);
  GetDistAoki(adj, A, dist_Aoki);
  ll ans = 0;
  vector<array<int, 2>> max_steps(N, {-1, -1});
  DFS(U, adj, dist_Aoki, 0, ans, max_steps);
  cout << ans << '\n';
}
