#include<stdio.h>
#define INF 10000000
void warshall_floyd(void);
int min(int,int);
int n,graph[101][101];

int main(void){
  int m,s,g1,g2,b1,b2,c,i,j,ans;
  
    while(scanf("%d %d %d %d %d",&n,&m,&s,&g1,&g2),n,m,s,g1,g2){
      
      for(i=0;i<=n;i++){
	for(j=0;j<=n;j++){
	  graph[i][j]=INF;
	}
	graph[i][i]=0;
      }
      
      for(i=0;i<m;i++){
	scanf("%d %d %d",&b1,&b2,&c);
	graph[b1][b2]=c;
      }

      warshall_floyd();
      for(i=0;i<=n;i++)
	ans=min(ans,graph[s][i]+graph[i][g1]+graph[i][g2]);

	printf("%d\n",ans);
    }
    
    return 0;
}

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

int min(int x,int y){
  return (x<y)?x:y;
}