#include <iostream>
using namespace std;

int main() {

  const long long int c_max = 10000000;

  long long int n, m, s, g1, g2, b1, b2, c;

  while( true ) {

    cin >> n >> m >> s >> g1 >> g2;

    if ( n == 0 ) break;
    s--;
    g1--;
    g2--;

    long long int map[100][100];

    for ( long long int i = 0; i < n; i++ ) {
      for ( long long int j = 0; j < n; j++ ) {
	if ( i == j ) {
	  map[i][j] = 0;
	}else {
	  map[i][j] = c_max;
	}
      }
    }

    for ( long long int i = 0; i < m; i++ ) {
      cin >> b1 >> b2 >> c;
      map[b1-1][b2-1] = c;
    }

    for ( long long int i = 0; i < n; i++ ) {
      for ( long long int j = 0; j < n; j++ ) {
	for ( long long int k = 0; k < n; k++ ) {
	  map[j][k] = min( map[j][k], map[j][i] + map[i][k] );
	}
      }
    }

    /*
    for ( long long int i = 0; i < n; i++ ) {
      for ( long long int j = 0; j < n; j++ ) {
	cout << map[i][j] << " ";
      }
      cout << endl;
    }
    */

    long long int ans = c_max;

    for ( long long int i = 0; i < n; i++ ) {
      ans = min( ans, map[s][i] + map[i][g1] + map[i][g2] );
    }

    cout << ans << endl;

  }

  return 0;

}