#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<cstdlib>
#include<list>
using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
#define rep2(i,n) for(i=1;i<=n;i++)

int main()
{
	int n,m,s,g1,g2;
	int i,j,k;
	int M=10000000;
	
	while(1){
		cin >> n >> m >> s >> g1 >> g2;
		if(n==0 && m == 0 && s ==0 && g1 ==0 &&g2==0) break;
		int a[101][101];
		int c[101][101];
		
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				a[i][j]=M;
				c[i][j]=M;
				if(i==j) c[i][j]=0;
			}
		}
		for(i=0;i<m;i++){
			int in1,in2,in3;
			cin >> in1 >> in2 >> in3;
			c[in1][in2] = in3;
		}
		
		for(k=1;k<=n;k++){
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
				}
			}
		}
		
		int mn=M;
		for(i=1;i<=n;i++){
			mn= min(mn, c[s][i] + c[i][g1] + c[i][g2]);
		}
		
		cout << mn << endl;
				
		
	}
	return 0;	
}