// Aizu 2005: Water Pipe Construction
// 2017.9.24 bal4u@uu

#include <stdio.h>
#include <string.h>
#define INF 0x7fffff

int dist[102][102];

int main()
{
	int n, m, s, g1, g2, b1, b2, c, i, j, k, x, ans;

	while (scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2) && n > 0) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) dist[i][j] = INF;
			dist[i][i] = 0;
		}
		for (i = 0; i < m; i++) {
			scanf("%d%d%d", &b1, &b2, &c);
			dist[b1][b2] = c;
		}
        for (k = 1; k <= n; k++) for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) {
			x = dist[i][k] + dist[k][j];
	        if (dist[i][j] > x) dist[i][j] = x;
        }
		for (ans = INF, i = 1; i <= n; i++) {
			if ((x = dist[s][i] + dist[i][g1] + dist[i][g2]) < ans) ans = x;
		}
		printf("%d\n", ans);
	}
	return 0;
}