INF = 1<<29
def dijkstra(pos, route, cost)
  arr = [pos]
  dist = [INF]*($n+1)
  dist[pos] = 0
  until arr.empty?
    a = arr.min{ |x, y| dist[x] <=> dist[y] }
    arr.delete(a)
    route[a].each do |b|
      d = dist[a] + cost[a][b]
      if (old = dist[b]) > d
        dist[b] = d
        if old == INF
          arr << b 
        end
      end
    end
  end
  dist
end

while l = gets
  $n, m, s, g1, g2 = l.split.map(&:to_i)
  break if $n == 0
  route = ($n+1).times.map{ [] }
  r_route = ($n+1).times.map{ [] }
  cost = ($n+1).times.map{ [0]*($n+1) }
  m.times do
    b1, b2, c = gets.split.map(&:to_i)
    route[b1] << b2; r_route[b2] << b1
    cost[b1][b2] = cost[b2][b1] = c
  end
  dist_s = dijkstra(s, route, cost)
  dist_g1 = dijkstra(g1, r_route, cost)
  dist_g2 = dijkstra(g2, r_route, cost)
  res = INF
  (1..$n).each{ |i| res = [res, dist_s[i] + dist_g1[i] + dist_g2[i]].min }
  p res
end