import scala.collection.mutable
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, m, s, t) = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(n){_ ⇒ Nil: List[(Int, Int)]}
  for (_ ← 0 until m){
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    edges(a - 1) ::= (b - 1, d)
    edges(a - 1) ::= (c - 1, d)
    edges(b - 1) ::= (a - 1, d)
    edges(b - 1) ::= (c - 1, d)
    edges(c - 1) ::= (a - 1, d)
    edges(c - 1) ::= (b - 1, d)
  }
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Long), Long](_._2).reverse).also{_.enqueue((s - 1, 0L))}
  val minMemo = Array.tabulate(n){_ ⇒ Long.MaxValue}.also{_(s - 1) = 0L }
  while (queue.head._1 != t - 1){
    val (top, distance) = queue.dequeue()
    if (minMemo(top) == distance) {
      for ((to, diff) ← edges(top)) {
        if (minMemo(to) > distance + diff) {
          minMemo(to) = distance + diff
          queue.enqueue((to, minMemo(to)))
        }
      }
    }
  }
  println(
    queue.head._2
  )
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
