MAX_COST = 100000
until (n, m, s, g1, g2 = gets.split.map(&:to_i)).all?(&:zero?)
  s -= 1
  g1 -= 1
  g2 -= 1
  matrix = Array.new(n){Array.new(n){MAX_COST}}
  n.times do |i|
    matrix[i][i] = 0
  end
  m.times do
    b1, b2, c = gets.split.map(&:to_i)
    b1 -= 1
    b2 -= 1
    matrix[b1][b2] = matrix[b2][b1] = c
  end
  n.times do |via|
    n.times do |start|
      n.times do |goal|
        matrix[start][goal] = [matrix[start][goal], matrix[start][via] + matrix[via][goal]].min
      end
    end
  end
  answer = MAX_COST
  n.times do |via|
    answer = [answer, matrix[s][via] + matrix[via][g1] + matrix[via][g2]].min
  end
  p answer
end