INF = 2 << 32
until (n, m, s, g1, g2 = gets.split(' ').map(&:to_i)).all?(&:zero?)
  cost = (n + 1).times.map {|i|
    a = Array.new(n + 1, INF)
    a[i] = 0
    a
  }
 
  m.times
    .lazy
    .map { gets.split(' ').map(&:to_i) }
    .each {|(b1, b2, c)| cost[b1][b2] = c }
 
  nr = 1..n
  nr.each {|k|
    nr.each {|i|
      nr.each {|j|
        cost[i][j] = [cost[i][j], cost[i][k] + cost[k][j]].min
      }
    }
  }
 
  min = INF
  nr.each {|k|
    min = [min, cost[s][k] + cost[k][g1] + cost[k][g2]].min
  }
  puts min
end