#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)

int d[100][100];
int main(){
	int n,m,s,g1,g2;
	while(cin>>n>>m>>s>>g1>>g2,n|m|s|g1|g2){
		s--;g1--;g2--;
		rep(i,n)rep(j,n)d[i][j]=INF;
		rep(i,n)d[i][i]=0;
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			d[a-1][b-1]=c;
		}
		rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		int ans=INF;
		rep(i,n){
			ans = min(ans,d[s][i]+d[i][g1]+d[i][g2]);
		}
		cout<<ans<<endl;
	}
	return 0;
}