#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

const int INF = 1 << 25;

bool solve() {
    int N, M, s, g1, g2;
    cin >> N >> M >> s >> g1 >> g2;
    if (N == 0) return false;

    --s, --g1, --g2;

    vector<vector<int>> dist(N, vector<int>(N, INF));
    for (int v = 0; v < N; ++v) dist[v][v] = 0;
    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        cin >> dist[--u][--v];
    }

    for (int j = 0; j < N; ++j) {
        for (int i = 0; i < N; ++i) {
            for (int k = 0; k < N; ++k) {
                dist[i][k] = min(dist[i][k], dist[i][j] + dist[j][k]);
            }
        }
    }

    int ans = INF;
    for (int v = 0; v < N; ++v) {
        ans = min(ans, dist[s][v] + dist[v][g1] + dist[v][g2]);
    }
    cout << ans << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

