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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	for (;;) {
		int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2;
		if (!n) break;

		vector<vector<ll>> dist(n + 1, vector<ll>(n + 1, 0x3f3f3f3f));

		rep(i, 1, n + 1) dist[i][i] = 0;

		rep(i, 0, m) {
			int b1, b2, c; cin >> b1 >> b2 >> c;
			dist[b1][b2] = c;
		}

		rep(i, 1, n + 1) rep(j, 1, n + 1) rep(k, 1, n + 1) {
			dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
		}

		ll ans = 0x3f3f3f3f;
		rep(i, 1, n + 1) {
			ans = min(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
		}
		cout << ans << endl;
	}
}

