loop do
    n, m, s, g1, g2 = gets.split.map(&:to_i)
    break if n == 0 || m == 0 || s == 0 || g1 == 0 || g2 == 0
    s -= 1
    g1 -= 1
    g2 -= 1
    cost = Array.new(n).map{Array.new(n, 10000001)}
    m.times do
        d = gets.split.map(&:to_i)
        cost[d[0]-1][d[1]-1] = d[2]
    end
    n.times do |k|
        n.times do |i|
            n.times do |j|
                next
                if i == j
                    cost[i][j] = 0
                    next
                end
                min = [cost[i][k] + cost[k][j], cost[i][j]].min
                cost[i][j] = min
            end
        end
    end
    min = 10000001
    n.times do |i|
        min = [min, cost[s][i] + cost[i][g1] + cost[i][g2]].min
    end
    puts min
end