#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m,s,t1,t2;
	while(cin>>n>>m>>s>>t1>>t2,n){
		s--;t1--;t2--;
		vvi G(n,vi(n,inf));
		rep(i,n)G[i][i]=0;
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			G[a][b]=c;
		}
		rep(k,n)rep(i,n)rep(j,n)
			G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
		int out=inf;
		rep(i,n)out=min(out,G[s][i]+G[i][t1]+G[i][t2]);
		cout<<out<<endl;
	}
}
 
 