#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define INF 1000000000000
typedef long long LL;
int n,m,s,g1,g2;
LL d[101][101];

int main(){
    while(cin>>n>>m>>s>>g1>>g2,n+m+s+g1+g2){
        s--;g1--;g2--;
        REP(i,101){
            REP(j,101){
                d[i][j]=INF;
            }
            d[i][i]=0;
        }
        REP(i,m){
            int a,b,c;
            cin>>a>>b>>c;
            a--;b--;
            d[a][b]=c;
            //d[b][a]=c;
        }
        REP(k,n){
            REP(i,n){
                REP(j,n){
                    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        LL ans=1e12;
        REP(i,n){
            ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
        }
        cout<<ans<<endl;
    }
    return 0;
}