import scala.annotation.tailrec

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)
  }
  println(
    calMultiple(points)
  )
  //Stack OverFlowになる
  def calSingle(points: Array[List[(Int, Int)]]): Double = {
    @tailrec
    def addStack(current: List[(Int, Double, List[(Int, Int)])]): List[(Int, Double, List[(Int, Int)])] = {
      current match {
        case (from, c, (next, cost)::t)::tail ⇒
          points(next).filter(_._1 != from) match {
            case nexts ⇒ addStack((next, cost.toDouble, nexts)::(from, c, t)::tail)
          }
        case _ => current
      }
    }
    var stack: List[(Int, Double, List[(Int, Int)])] = addStack(List((0, 0d, points(0))))
    var result = 0d
    while (stack.nonEmpty){
      stack match {
        case (_, res, Nil)::Nil ⇒
          result = res
          stack = Nil
        case (_, res, Nil)::(from, c, t)::tail ⇒
          stack = addStack((from, c + res * p, t)::tail)
        case _ ⇒ ???
      }
    }
    result
    //points(current).withFilter{case (to, _) ⇒ to != from}.map{case (to, cost) ⇒ calSingle(to, current).let{it ⇒ (it + cost) * p}}.sum
  }
  def calMultiple(points: Array[List[(Int, Int)]]): Double = {
    @tailrec
    def addStack(current: List[(Int, Double, Double, List[(Int, Int)])]): List[(Int, Double, Double, List[(Int, Int)])] = {
      current match {
        case (from, m, c, (next, cost)::t)::tail ⇒
          points(next).filter(_._1 != from) match {
            case nexts ⇒ addStack((next, 1d, cost.toDouble, nexts)::(from, m, c, t)::tail)
          }
        case _ ⇒ current
      }
    }
    var stack: List[(Int, Double, Double, List[(Int, Int)])] = addStack((List((0, 1d, 0d, points(0)))))
    var result = 0d
    while (stack.nonEmpty){
      stack match {
        case (_, m, c, Nil)::Nil ⇒
          val single = calSingle(points)
          result = m * single + c
          stack = Nil
        case (_, m, c, Nil)::(from, mm, cc, t)::tail ⇒
          stack = addStack((from, mm + m * p, cc + c * p, t)::tail)
        case _ ⇒ ???
      }
    }
    result
    //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)
  }
}
