#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<29)

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2) {
		if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0) break;
		n; m; s--; g1--; g2--;
		vector<vector<int>> dist(n, vector<int>(n, INF));
		for (int i = 0; i < m;i++) {
			int b1, b2, c; cin >> b1 >> b2 >> c;
			b1--; b2--;
			dist[b1][b2] = c;
		}

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

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