#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1e8;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;

typedef unsigned long long ll;
int main(){
	int N,M,s,g1,g2;
	while(scanf("%d%d%d%d%d",&N,&M,&s,&g1,&g2),N){
		--s;--g1;--g2;
		int dp[128][128];
		rep(i,128){
			rep(j,128){
				if(i == j){
					dp[i][j] = 0;
				}
				else{
					dp[i][j] = INF;
				}
			}
		}
		rep(i,M){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			--a;--b;
			dp[a][b] = c;
		}

		rep(k,N){
			rep(i,N){
				rep(j,N){
					dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}

		int ans = INF;

		rep(i,N){
			ans = min(ans,dp[s][i]+dp[i][g1]+dp[i][g2]);
		}
		printf("%d\n",ans);
	}
	return 0;
}