#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
long long mod_pow(long long N, long long M) {
  if (M == 0) return 1;
  long long res = mod_pow((N * N) % MOD, M / 2);
  if (M & 1) res = (res * N) % MOD;
  return res %= MOD;
}
int gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
vector<vector<int>> Edge(100005);
vector<int> dist_takahashi(100005, 100100);
vector<int> dist_aoki(100005, 100100);
vector<bool> seen(100005);
void dfs_takahashi(int from, int dist) {
  seen.at(from) = true;
  dist_takahashi.at(from) = dist;
  for (int V : Edge.at(from)) {
    if (seen.at(V)) continue;
    dfs_takahashi(V, dist + 1);
  }
}
void dfs_aoki(int from, int dist) {
  seen.at(from) = true;
  dist_aoki.at(from) = dist;
  for (int V : Edge.at(from)) {
    if (seen.at(V)) continue;
    dfs_aoki(V, dist + 1);
  }
}
int ans = 0;
void tag_game(int from, int maxidist) {
  seen.at(from) = true;
  ans = max(ans, maxidist);
  if (dist_takahashi.at(from) >= dist_aoki.at(from)) {
    return;
  }
  for (int V : Edge.at(from)) {
    if (seen.at(V)) continue;
    tag_game(V, maxidist + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  int takahashi, aoki;
  cin >> takahashi >> aoki;
  takahashi--;
  aoki--;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    Edge.at(a).push_back(b);
    Edge.at(b).push_back(a);
  }
  dfs_takahashi(takahashi, 0);
  fill(seen.begin(), seen.end(), false);
  dfs_aoki(aoki, 0);
  fill(seen.begin(), seen.end(), false);
  tag_game(takahashi, 0);
  cout << ans << "\n";
  ;
}
