
object Main extends App {

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


  val p = readLine.trim.toDouble
  val n = readLine.trim.toInt
  val points = Array.tabulate(n){_ ⇒ Nil:List[(Int, Int)]}
  for (_ ← 1 until n){
    val Array(x, y, c) = readLine.trim.split(' ').map(_.toInt)
    points(x - 1) ::= (y - 1, c)
    points(y - 1) ::= (x - 1, c)
  }

  val (m, c) = calMultiple(0)
  val single = calSingle(0)
  println(
    m * single + c
  )
  def calSingle(current: Int, from: Int = 0): Double = {
    points(current).withFilter{case (to, _) ⇒ to != from}.map{case (to, cost) ⇒ calSingle(to, current).let{it ⇒ (it + cost) * p}}.sum
  }
  def calMultiple(current: Int, from: Int = 0): (Double, Double) = {
    points(current).withFilter{case (to, _) ⇒ to != from}.map{case (to, cost) ⇒ calMultiple(to, current).let{case (m, c) ⇒ (m * p, (c + cost) * p)}}.foldLeft((0d, 0d):(Double, Double)){case ((m, c), (m2, c2)) ⇒ (m + m2, c + c2)}.let{case (m, c) ⇒ (m + 1, c)}
  }
  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)
  }
}
