#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define ll long long
const int INF = 2 << 27;

int main() {
  while(1){
    int n,m,s,g1,g2;
    cin >> n >> m >> s >> g1 >> g2;
    if(n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0) break;
    s--;
    g1--;
    g2--;
    int cost[n][n];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(i == j) {
          cost[i][j] = 0;
        }
        else {
          cost[i][j] = INF;
        }
      }
    }
    for(int i = 0; i < m; i++) {
      int b1,b2,c;
      cin >> b1 >> b2 >> c;
      cost[b1-1][b2-1] = c;
    }


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

    int ans = INF;
    for(int i = 0; i < n; i++) {
      ans = min(ans,cost[s][i] + cost[i][g1] + cost[i][g2]);
    }
    cout << ans << endl;
  }

}