#include <bits/stdc++.h>
using namespace std;
using Graph= vector<vector<int>>;
const int TBC= -1;

void DFS(const Graph &tree, int parent, int root, vector<int> *parents, vector<int> *pre_timestamp, vector<int> *post_timestamp, vector<int> *depth){
  if(parents->at(root)==TBC){
    parents->at(root)= parent;
    pre_timestamp->at(root)= depth->size();
  }
  int depth_root= (!depth->empty()) ? depth->back()+ 1
                                    : 0;
  depth->emplace_back(depth_root);
  for(auto child:tree.at(root)){
    if(child != parent){
      DFS(tree, root, child, parents, pre_timestamp, post_timestamp, depth);
      depth->emplace_back(depth_root);
    }
  }
  post_timestamp->at(root)= depth->size();
}

int main(){
  int N,v0_runner,v0_trailer;
  cin >> N >> v0_runner >> v0_trailer;
  const int M= N-1;
  v0_runner--; v0_trailer--; // 1-indexed -> 0-indexed

  Graph tree(N);

  int v1,v2;
  for(int i=0; i<M; i++){
    cin >> v1 >> v2;
    v1--; v2--; // 1-indexed -> 0-indexed
    tree.at(v1).emplace_back(v2);
    tree.at(v2).emplace_back(v1);
  }

  vector<int> parents(N, TBC);
  vector<int> pre_timestamp(N, TBC);
  vector<int> post_timestamp(N, TBC);
  vector<int> depth;

  DFS(tree, -1, v0_trailer, &parents, &pre_timestamp, &post_timestamp, &depth);

  int depth0_runner= depth.at(pre_timestamp.at(v0_runner));
  int cnt_up= (depth0_runner- 1)/ 2;
  int pos_runner= v0_runner;
  for(int i=0; i<cnt_up; i++){
    pos_runner= parents.at(pos_runner);
  }

  int depth1_runner= depth.at(pre_timestamp.at(pos_runner));
  int left = pre_timestamp.at(pos_runner);
  int right= post_timestamp.at(pos_runner);
  int depth_tree= *max_element(depth.begin()+ left, depth.begin()+ right);

  int ans= (depth0_runner/ 2)+ (depth_tree- depth1_runner);

  cout << ans << endl;
}
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;

  vvll to(N);
  rep(i, N - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].pb(b);
    to[b].pb(a);
  }

  queue<P> q1;
  q1.push({u, 1});
  vll d1(N);
  while (!q1.empty()) {
    ll index = q1.front().first;
    ll distance = q1.front().second;
    q1.pop();
    if (d1[index] != 0) continue;
    d1[index] = distance;
    rep(i, to[index].size()) {
      q1.push({to[index][i], distance + 1});
    }
  }

  debugV(d1);

  queue<P> q2;
  q2.push({v, 1});
  vll d2(N);
  while (!q2.empty()) {
    ll index = q2.front().first;
    ll distance = q2.front().second;
    q2.pop();
    if (d2[index] != 0) continue;
    d2[index] = distance;
    rep(i, to[index].size()) {
      q2.push({to[index][i], distance + 1});
    }
  }

  debugV(d2);

  ll ans = 0;
  rep(i, N) {
    if (d1[i] < d2[i]) ans = max(ans, d2[i]);
  }
  ans--;
  ans--;
  COUT(ans);
  return 0;
}