// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

const int INF = 1 << 28;

int main()
{
  int N, M, S, G1, G2;
  while (N = in(), M = in(), S = in() - 1, G1 = in() - 1, G2 = in() - 1, N){
    int way[111][111];
    for (int i = 0; i < N; i++) fill_n(way[i], N, INF), way[i][i] = 0;

    for (int i = 0; i < M; i++){
      int b1 = in() - 1, b2 = in() - 1, c = in();
      way[b1][b2] = c;
    }
    for (int k = 0; k < N; k++){
      for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
          way[i][j] = min(way[i][j], way[i][k] + way[k][j]);
        }
      }
    }
    int mini = INF;
    for (int i = 0; i < N; i++){
      mini = min(mini, way[S][i] + way[i][G1] + way[i][G2]);
    }
    printf("%d\n", mini);
  }

  return 0;
}