// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2005
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

const int INF = 1<<28;

int main(){

  for(int n,m,s,g1,g2;cin>>n>>m>>s>>g1>>g2,n;){
    vector<vector<int>> d(n, vector<int> (n, INF));

    // directed graph
    for(int i=0,b1,b2,c;i<m;++i){
      cin>>b1>>b2>>c;
      d[b1-1][b2-1] = c;
    }

    for(int i=0;i<n;++i) d[i][i] = 0;

    for(int k=0;k<n;++k)
      for(int i=0;i<n;++i)
        for(int j=0;j<n;++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    int ans = INT_MAX;
    for(int i=0;i<n;++i) ans = min(ans, d[s-1][i] + d[i][g1-1] + d[i][g2-1]);

    cout << ans << endl;
  }

  return 0;
}