#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, m, s, g, gg, from, to, cost;
  while(cin >> n >> m >> s >> g >> gg, n){
    s--;g--;gg--;
    vector<vector<int> > graph(n, vector<int>(n, 1e8));
    for(int i = 0; i < m; i++){
      cin >> from >> to >> cost;
      from--;to--;
      graph[from][to] = cost;
    }
    for(int i = 0; i < n; i++) graph[i][i] = 0;
    for(int k = 0; k < n; k++){
      for(int i = 0; i < n; i++){
	for(int j = 0; j < n; j++){
	  graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j]);
	}
      }
    }
    int ans = 1e9;
    for(int i = 0; i < n; i++){
      ans = min(ans, graph[s][i]+ graph[i][g] + graph[i][gg]);
    }
    cout << ans << endl;
  }
}