#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

int main() {
	int n, m, s, g1, g2;
	while(cin >> n >> m >> s >> g1 >> g2, n) {
		int cost[101][101];
		rep(i,n+1) rep(j,n+1) cost[i][j] = 10000000;
		rep(i, m) {
			int a, b, c;
			cin >> a >> b >> c;
			cost[a][b] = c;
		}
		rep(i,n) cost[i+1][i+1] = 0;
		rep(k,n) rep(i,n) rep(j,n)
			cost[i+1][j+1] = min( cost[i+1][j+1], cost[i+1][k+1] + cost[k+1][j+1] );
		int res = 10000000;
		for(int k=1; k<=n; k++) {
			res = min(res, cost[s][k]+cost[k][g1]+cost[k][g2]);
		}
		cout << res << endl;
	}
	return 0;
}