fun main(args:Array<String>):Unit{
    while (true){
        val (n, m, s, t1, t2) = readLine()!!.split(' ').map(String::toInt)
        if (n == 0 && m == 0 && s == 0 && t1 == 0 && t2 == 0) break
        val minCost = Array(n){from -> Array(n){to -> if (from == to) 0 else Int.MAX_VALUE.toLong()}}
        repeat(m){
            val (b1, b2, c) = readLine()!!.split(' ').map(String::toInt)
            if (minCost[b1 - 1][b2 - 1] > c){
                minCost[b1 - 1][b2 - 1] = c.toLong()
            }
        }
        for (mid in 0 until n) for (from in 0 until n) for (to in 0 until n){
            if (minCost[from][to] > minCost[from][mid] + minCost[mid][to])
                minCost[from][to] = minCost[from][mid] + minCost[mid][to]
        }
        println((0 until n).map{mid ->
            minCost[s - 1][mid] + minCost[mid][t1 - 1] + minCost[mid][t2 - 1]
        }.min()!!)
    }
}
