#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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 ll MOD = 1000000007;
const ll INF = 9999999999;
void dfs(Graph &G, int v, vector<bool> &seen, int mokuteki,
         vector<int> &depth) {
  seen.at(v) = true;
  for (auto nv : G.at(v)) {
    if (seen.at(nv)) continue;
    if (nv == mokuteki) continue;
    depth.at(nv) = depth.at(v) + 1;
    dfs(G, nv, seen, mokuteki, depth);
  }
  return;
}
void dfsdis(Graph &G, int v, vector<bool> &seen, int mokuteki,
            vector<int> &depth) {
  seen.at(v) = true;
  for (auto nv : G.at(v)) {
    if (seen.at(nv)) continue;
    dfsdis(G, nv, seen, mokuteki, depth);
    if (depth.at(nv) != -1) depth.at(v) = depth.at(nv) + 1;
  }
  return;
}
int main() {
  int N, U, V;
  cin >> N >> U >> V;
  U--;
  V--;
  Graph G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  int ans = 0;
  vector<bool> seen(N, false);
  vector<int> depths(N, -1);
  depths.at(U) = 0;
  dfsdis(G, V, seen, U, depths);
  int inidis = depths.at(V);
  for (int i = 0; i < (inidis - 1) / 2; i++) {
    for (int i = 0; i < N; i++) {
      depths.at(i) = -1;
      seen.at(i) = false;
    }
    depths.at(V) = 0;
    dfsdis(G, U, seen, V, depths);
    for (int i = 0; i < N; i++) {
      if (depths.at(i) == depths.at(U) - 1) {
        U = i;
        break;
      }
    }
    for (int i = 0; i < N; i++) {
      depths.at(i) = -1;
      seen.at(i) = false;
    }
    depths.at(U) = 0;
    dfsdis(G, V, seen, U, depths);
    for (int i = 0; i < N; i++) {
      if (depths.at(i) == depths.at(V) - 1) {
        V = i;
        break;
      }
    }
    ans++;
  }
  int bufV = V;
  if (inidis % 2 == 0) {
    for (int i = 0; i < N; i++) {
      depths.at(i) = -1;
      seen.at(i) = false;
    }
    depths.at(U) = 0;
    dfsdis(G, V, seen, U, depths);
    for (int i = 0; i < N; i++) {
      if (depths.at(i) == depths.at(V) - 1) {
        V = i;
        break;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    depths.at(i) = -1;
    seen.at(i) = false;
  }
  depths.at(U) = 0;
  dfs(G, U, seen, V, depths);
  int maxdep = 0;
  for (int i = 0; i < N; i++) {
    maxdep = max(maxdep, depths.at(i));
  }
  ans += maxdep;
  if (inidis % 2 == 0) {
    ans++;
  }
  cout << ans << endl;
}
