;; F - Playing Tag on Tree

(defun main ()
  (let* ((N (read))  ; 頂点数
         (u (read))  ; 高橋君の位置
         (v (read))  ; 青木君(鬼)の位置
         (tree (read-tree N)))
    (princ (solve N (1- u) (1- v) tree))
    (fresh-line)))

(defun solve (N u v tree)
  (let* ((distance (distances-from v tree)) ; vから各頂点までの距離
         (dist-v-u (aref distance u)) ; vからuまでの距離
         (margin (floor (1- dist-v-u) 2)) ; 捕まらずにvまで近づける距離
         (max-dist (max-distance u margin tree distance)))
    (1- max-dist))) ; 最大距離-1 の頂点で捕まる

(defun max-distance (u margin tree distance)
  "distanceがmargin以下の頂点を通らずに,
   uから到達可能な頂点のdistanceの最大値"
  (let* ((N (array-dimension tree 0)) ; 頂点数
         (visited (make-array N :initial-element nil)) ; 訪問済?
         (max (aref distance u))) ; 現時点の最大値
    (labels ((dfs (v)
               (unless (aref visited v)
                 (setf (aref visited v) t)
                 (when (< max (aref distance v))
                       (setf max (aref distance v)))
                 (loop for next in (aref tree v) ; vの隣接頂点
                   when (> (aref distance next) margin)
                     do (dfs next)))))
      (dfs u)
      max)))

(defun distances-from (v tree)
  "頂点vから各頂点までの距離を表す配列を返す"
  (let* ((N (array-dimension tree 0)) ; 頂点数
         (distance (make-array N)) ; 各頂点までの距離
         (visited  (make-array N :initial-element nil))) ; 訪問済?
    (labels ((dfs (u dist)
               (unless (aref visited u)
                 (setf (aref visited u) t)
                 (setf (aref distance u) dist) ; uまでの距離
                 (loop for next in (aref tree u) ; uの隣接頂点
                   do (dfs next (1+ dist))))))
      (dfs v 0)
      distance)))

(defun read-tree (N)
  "N頂点の木をreadして作る. 頂点番号は0〜N-1"
  (let ((tree (make-array N))) ; 隣接リスト
    (loop for i below N do (setf (aref tree i) nil))
    (loop repeat (1- N)
      do (let ((a (read-fixnum))
               (b (read-fixnum)))
           (push (1- b) (aref tree (1- a)))
           (push (1- a) (aref tree (1- b)))))
    tree))

(defun read-fixnum (&optional (in *standard-input*))
  "readより速い整数専用read. 
   参考: 競技プログラミングでCommon Lispを使っている人と
   これから使うかもしれない人のために, @sansaqua
   https://qiita.com/sansaqua/items/0b6417cb541047e29da4"
  (loop with acc = 0
        with minus = nil
        with started = nil
        for byte = (read-byte in)
        if (<= 48 byte 57)
          do (setf acc (+ (* acc 10) (- byte 48)))
             (setf started t)
        else if started
          return (if minus (- acc) acc)
        else if (= byte 45)
          do (setf minus t)))

(main)
