#include <bits/stdc++.h>
#define inf 1000000;
using namespace std;

int n, m, s, g[2] = {0};
int memo[105][105] = {0};

int solve();

int main() {
  while(1) {
    cin >> n >> m >> s >> g[0] >> g[1];
    --s, --g[0], --g[1];
    if(n + m == 0) break;
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j) memo[i][j] = inf;
    for(int i = 0; i < m; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      memo[a][b] = c;
    }

    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  int ans = inf;
  for(int i = 0; i < n; ++i) memo[i][i] = 0;
  for(int k = 0; k < n; ++k)
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        memo[i][j] =
            min(memo[i][j], memo[i][k] + memo[k][j]);
  for(int i = 0; i < n; ++i)
    ans = min(ans,
              memo[s][i] + memo[i][g[0]] + memo[i][g[1]]);
  return ans;
}
