#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const int inf=1e8;
using namespace std;
int main(){
  int a,b,c,d,e;
  while(cin>>a>>b>>c>>d>>e,a+b+c+d+e){
    c--;d--;e--;
    vector<vector<int> >cost(a,vector<int>(a));
    rep(i,a)rep(j,a){
      if(i==j)cost[i][j]=0;
      else cost[i][j]=inf;
    }
    rep(i,b){
      int f,g,h;
      cin>>f>>g>>h;
      f--;g--;
      cost[f][g]=h;
    }
    rep(k,a)rep(i,a)rep(j,a)
      cost[i][j]=min(cost[i][k]+cost[k][j],cost[i][j]);
    int mi=inf;
    rep(i,a)mi=min(mi,cost[c][i]+cost[i][d]+cost[i][e]);
    cout<<mi<<endl;
  }
}