#include <iostream>
#include <algorithm>

using namespace std;

const int inf = 999999;

int main()
{
	int n, m, s, t, u, a[101][101], p, q, v;
	
	while(cin>>n>>m>>s>>t>>u&&n){
		fill(&a[0][0], &a[100][100], inf);
		for(int i = 0; i <= n; i++){
			a[i][i] = 0;
		}
		
		while(m--){
			cin >> p >> q;
			cin >> a[p][q];
		}
		
		for(int k = 1; k <= n; k++){
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
				}
			}
		}
		
		m = inf;
		for(int i = 1; i <= n; i++){
			m = min(m, a[s][i]+a[i][t]+a[i][u]);
		}
		
		cout << m << endl;
	}
	
	return 0;
}