#include<iostream> 
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define INF 1<<29
#define MAX 3000
using namespace std;int cost[MAX][MAX],V,d[MAX];bool used[MAX];void dijkstra(int);int main(){int m,s,g1,g2,b1,b2,c;while(true){cin >> V >> m >> s >> g1 >> g2;if(V == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)break;for(int i=1;i<=V;i++){for(int j=1;j<=V;j++){cost[i][j]=INF;}}for(int i=0;i<m;i++){cin >> b1 >> b2 >> c;cost[b1][b2]=c;}dijkstra(s);int ans = d[g1]+d[g2];int dr[MAX];for(int i=1;i<=V;i++)dr[i]=d[i];for(int i=1;i<=V;i++){if(i == s)continue;dijkstra(i);ans = min(ans,dr[i]+d[g1]+d[g2]);}cout << ans << endl;}}void dijkstra(int s){for(int i=1;i<=V;i++){d[i]=INF;used[i]=false;}d[s] = 0;while(true){int v=-1;for(int u=1;u<=V;u++){if(!used[u] && (v == -1 || d[u] < d[v]))v = u;}if(v == -1)break;used[v]=true;for(int u=1;u<=V;u++){d[u]=min(d[u],d[v]+cost[v][u]);}}}