#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const int INF = INT_MAX / 4;

int main(void) {
	int n, m, s, g1, g2;
	
	while (cin >> n >> m >> s >> g1 >> g2, n) {
		s--; g1--; g2--;

		VVI es(n, VI(n, INF));
		for (int i = 0; i < m; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a--; b--;
			es[a][b] = c;
		}
		for (int i = 0; i < n; i++) {
			es[i][i] = 0;
		}

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					es[i][j] = min(es[i][j], es[i][k] + es[k][j]);
				}
			}
		}

		int ans = INF;
		for (int i = 0; i < n; i++) {
			ans = min(ans, es[s][i] + es[i][g1] + es[i][g2]);
		}

		cout << ans << endl;
	}

	return 0;
}