#include<iostream>
#include<algorithm>
using namespace std;

const int INF=1<<27;

int main(){
  int n,m,s,g1,g2;
  while(cin>>n>>m>>s>>g1>>g2,n){
    s--;g1--;g2--;
    int dik[100][100];
    for(int i=0;i<n;i++) 
      for(int j=0;j<n;j++)
	if(i == j )dik[i][j] = 0;
	else dik[i][j]=INF;
    while(m--){
      int b1,b2,c;
      cin>>b1>>b2>>c;
      dik[b1-1][b2-1]=c;
    }

    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  dik[i][j]=min(dik[i][j],dik[i][k]+dik[k][j]);
    int ans=dik[s][g1]+dik[s][g2];
    for(int i=0;i<n;i++) ans = min(ans,dik[s][i]+dik[i][g1]+dik[i][g2]);
    cout<<ans<<endl;
  }
}