#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define	INF 100000000;
using namespace std;
int mp[1001][1001];
int d[1001][1001];
int n,m,s,g1,g2;


int main() {
 


  while(1) {
    cin >> n >> m >> s >> g1 >> g2;
    if(n==0&&m==0&&s==0&&g1==0&&g2==0)break;

    for(int i=0;i<=n;i++) 
      for(int j=0;j<=n;j++)
	if(i == j) mp[i][j] = 0;
	else mp[i][j] = INF;

    for(int i=0;i<m;i++) {
      int b1,b2,c;
      cin >> b1 >> b2 >> c;
      mp[b1][b2] = c;
    }
    for(int k=1;k<=n;k++)
      for(int i=1;i<=n;i++) 
	for(int j=1;j<=n;j++)
	  mp[i][j] = min(mp[i][j] ,mp[i][k]+mp[k][j]);

    long long  ans = INF;
    for(int i=1;i<=n;i++){
      int sum = 0;
      sum = mp[s][i];
      sum += mp[i][g1];
      sum += mp[i][g2];
	if(ans > sum) ans = sum;
    }
    cout << ans << endl;
    
  }
  
  
  return 0;
}