import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, t, a = in.next().toInt
  val tree = Array.fill[List[Int]](N+1)(Nil)
  for (_ <- 1 to N-1) {
    val A, B = in.next().toInt
    tree(A) = B :: tree(A)
    tree(B) = A :: tree(B)
  }

  //
  val fromA = Array.fill[Int](N+1)(-1)

  val q = new Queue[(Int, Int)] // (node, dist)
  q.enqueue((a, 0))

  while(!q.isEmpty) {
    val (now, dist) = q.dequeue()
    fromA(now) = dist
    for (e <- tree(now) if fromA(e) == -1) {
      q.enqueue((e, dist+1))
    }
  }

  // taka
  q.clear()
  var ans = fromA(t)

  val dp = new Array[Boolean](N+1)
  q.enqueue((t, 0))

  while(!q.isEmpty) {
    val (now, dist) = q.dequeue()

    if (!dp(now) && dist < fromA(now)) {
      dp(now) = true
      ans = Math.max(ans, fromA(now))
      for (e <- tree(now) if !dp(e)) {
        q.enqueue((e, dist+1))
      }
    }
  }

  println(ans - 1)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
