#include<stdio.h>
#include<limits.h>
int main()
{
	int n,m,s,g1,g2,b1,b2,c,i,j,k,d[101][101],V=INT_MAX/5;
	while(scanf("%d%d%d%d%d",&n,&m,&s,&g1,&g2),n)
	{
		for(i=1;i<=n;d[i][i]=0,++i)for(j=1;j<=n;++j)d[i][j]=V;
		while(m--)scanf("%d%d%d",&b1,&b2,&c),d[b1][b2]=c;
		for(k=1;k<=n;++k)for(i=1;i<=n;++i)for(j=1;j<=n;++j)
			c=d[i][k]+d[k][j],d[i][j]=(d[i][j]<c?d[i][j]:c);
		for(c=V,i=1;i<=n;++i)
			k=d[s][i]+d[i][g1]+d[i][g2],c=(c<k?c:k);
		printf("%d\n",c);
	}
	return 0;
}