
import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._
  solve
  @tailrec
  def solve: Unit = {
    val n = readLine.trim.toInt
    if (n == 0) return
    var edges = List.tabulate(n){_ ⇒
      val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
      (a, b, c)
    }
    val citySize = edges.flatMap{i ⇒ List(i._1, i._2)}.max + 1
    val minDistance: Array[Array[Long]] = Array.tabulate(citySize){f ⇒
      Array.tabulate(citySize){t ⇒ if (f == t) 0L else Int.MaxValue.toLong}
    }
    for ((a, b, c) ← edges){
      minDistance(a)(b) = math.min(minDistance(a)(b), c)
      minDistance(b)(a) = math.min(minDistance(b)(a), c)
    }
    for (k ← 0 until citySize; i ← 0 until citySize; j ← 0 until citySize if minDistance(i)(j) > minDistance(i)(k) + minDistance(k)(j)){
      minDistance(i)(j) = minDistance(i)(k) + minDistance(k)(j)
    }
    println(minDistance.indices.minBy(i ⇒ minDistance(i).sum).let{i ⇒ s"$i ${minDistance(i).sum}"})
    solve
  }

  implicit class Extention[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
