
#include<iostream>
#include<vector>
#include<queue>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define INF (1<<28)
#define mk make_pair
#define fs first
#define sc second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int n,m,s,g,h;

int v[100][100];

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ",";
	out << "}" << endl;
}

int main(){
	while(cin >> n >> m >> s >> g >> h, n){
		rep(i,100)rep(j,100) v[i][j] = i==j?0:INF;
		int ans = INF;
		s--; g--; h--;
		rep(i,m){
			int x, y, c;
			cin >> x >> y >> c;
			v[x-1][y-1] = c;
		}
		
		rep(k,n) rep(i,n) rep(j,n) v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
		
		rep(i,n){
			ans = min (ans, v[s][i] + v[i][g] + v[i][h]);
		}
		cout << ans << endl;
	}
	return 0;
}