loop {
    n, m, s, g1, g2 = gets.split.map &:to_i
    break if n == 0
    cost = (1..n).map{ [Float::INFINITY] * n }  
    (0..n-1).each{|i| cost[i][i] = 0}
    m.times {
        i, j, c = gets.split.map &:to_i
        cost[i-1][j-1] = c
    }
    (0..n-1).each{|k|
        next_cost = (1..n).map{ Array.new(n) }  
        (0..n-1).each{|i|
            (0..n-1).each{|j|
                x = cost[i][j]
                y = cost[i][k] + cost[k][j]
                next_cost[i][j] = (x < y ? x : y)
            }   
        }       
        cost = next_cost
    }   
    p (0..n-1).map{|k| cost[s-1][k] + cost[k][g1-1] + cost[k][g2-1]}.min
}