object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m, r = sc.nextInt()
  val rs = List.fill(r)(sc.nextInt()-1)
  val e = List.fill(m)((sc.nextInt()-1, sc.nextInt()-1, sc.nextInt()))

  def shortestPath(n: Int, edges: Seq[(Int, Int, Int)]): Array[Array[Int]] = {
    val ans = Array.tabulate(n,n)((i,j) => if (i == j) 0 else -1)
    for ((u, v, l) <- edges) {
      ans(u)(v) = l
      ans(v)(u) = l
    }

    for {
      k <- 0 until n
      i <- 0 until n
      j <- 0 until n
      if ans(i)(k) != -1 && ans(k)(j) != -1 &&
        (ans(i)(j) == -1 || ans(i)(k) + ans(k)(j) < ans(i)(j))
    } {
      ans(i)(j) = ans(i)(k) + ans(k)(j)
    }
    ans
  }

  val sp = shortestPath(n, e)
  val ans = rs.permutations.map(_.sliding(2).map{case List(x1, x2) => sp(x1)(x2)}.sum).min
  println(ans)
}
