import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}

void main() {
	auto r1 = readInts();
	int n = r1[0];
	int m = r1[1];
	int s = r1[2];
	auto g = r1[3..$];
	while(n) {
		auto d = new int[][](101,101);
		foreach(di; d){
			di.fill(int.max/1000);
		}
		foreach(i; 0..n) {
			d[i][i] = 0;
		}
		foreach(i; 0..m) {
			auto r2 = readInts();
			d[r2[0]][r2[1]] = r2[2];
		}
		foreach(k; 0..n) {
			foreach(i; 0..n) {
				foreach(j; 0..n) {
					d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
				}
			}
		}
		int ans = int.max;
		foreach(i; 0..n) {
			ans = min(ans, d[s][i] + d[i][g[0]] + d[i][g[1]]);
		}
		writeln(ans);
		r1 = readInts();
		n = r1[0];
		m = r1[1];
		s = r1[2];
		g = r1[3..$];
	}
}