import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

bool solve() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = s[2]-1;
    auto G1 = s[3]-1;
    auto G2 = s[4]-1;
    if (N == 0) return false;

    auto D = new int[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) D[i][j] = i == j ? 0 : 1 << 29;

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        D[s[0]-1][s[1]-1] = s[2];
    }

    foreach (i; 0..N)
        foreach (j; 0..N)
            foreach (k; 0..N)
                D[j][k] = min(D[j][k], D[j][i] + D[i][k]);

    N.iota.map!(i => D[S][i] + D[i][G1] + D[i][G2]).reduce!min.writeln;

    return true;
}

void main() {
    while (solve()) {}
}

