#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;
int d[101][101];

int main(){
	int n,m,s,g1,g2;
	while(cin >> n >> m >> s >> g1 >> g2){
		if(n==0&&m==0&&s==0&&g1==0&&g2==0) break;
		for(int i=1; i<=n; ++i){
			for(int j=1; j<=n; ++j){
				if(i==j){
					d[i][j]=0;
				} else {
					d[i][j]=INF;
				}
			}
		}
		for(int i=0; i<m; ++i){
			int b1,b2,c;
			cin >> b1 >> b2 >> c;
			d[b1][b2]=c;
			//d[b2][b1]=c;
		}
		for(int k=1; k<=n; ++k){
			for(int i=1; i<=n; ++i){
				for(int j=1; j<=n; ++j){
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		int ans=INF;
		for(int i=1; i<=n; ++i){
			ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
		}
		cout << ans << "\n";
	}
	return 0;
}