/*
Author: Le_bach Ngo Quyen High School
*/
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
//#define Lebach
#define OFFLINE
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define N 100005
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define REP(i, b) for(int i = 1; i <= b; i++)
#define FORD(i,a,b) for(int i = a; i >= b; i--)
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define cnt_bits __builtin_popcountll
#define all_subset(mask) (1 << mask)
#define is_bit(pos, mask) ((mask >> pos) & 1)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define multitest 0
#ifdef Lebach
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef pair<int, int> pii;
/*--------------------------------------------------------------------------------------------------------------------------*/
/// Init
int n, m, s, t1, t2, ans, opti_t;
vector<vector<pair<int, int>>> graph(n);
vector<int> d;
/*--------------------------------------------------------------------------------------------------------------------------*/
void Read(){
cin >> m >> n >> s >> t1 >> t2;
graph.resize(n+1);
d.resize(n+3, INF);
for(int i = 1; i <= m; i++){
int u, v, w;
cin >> u >> v >> w;
graph[u].push_back({v,w});
graph[v].push_back({u,w});
}
}
void dis(int node1){
d[node1] = 0;
priority_queue<pii, vector<pii>, greater<pii>> q;
q.push({node1, d[node1]});
while(!q.empty()){
int v = q.top().ff;
int d_v = q.top().ss;
q.pop();
if(d_v != d[v]) continue;
for(auto edge: graph[v]){
int v1 = edge.ff;
int d_v1 = edge.ss;
if(d[v] + d_v1 < d[v1]){
d[v1] = d[v] + d_v1;
q.push({v1, d[v1]});
}
}
}
}
void solve() {
dis(s);
if(d[t1] > d[t2]){
opti_t = t2;
ans += d[t2];
d.resize(n+3, INF);
dis(opti_t);
ans += d[t1];
} else {
opti_t = t1;
ans += d[t1];
d.resize(n+3, INF);
dis(opti_t);
ans += d[t2];
}
cout << ans;
}
/*--------------------------------------------------------------------------------------------------------------------------*/
void Combination_system(){
Read();
solve();
return;
}
int main() {
#define NAME "TASK"
if(fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
fastio();
if(multitest){
int T; cin >> T;
while(T--)
Combination_system();
} else Combination_system();
return 0;
}
LyoKICAgIEF1dGhvcjogTGVfYmFjaCBOZ28gUXV5ZW4gSGlnaCBTY2hvb2wKKi8KCi8vI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk8zLHVucm9sbC1sb29wcyIpCi8vI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKLy8jcHJhZ21hIEdDQyBvcHRpbWl6YXRpb24oInVucm9sbC1sb29wcywgbm8tc3RhY2stcHJvdGVjdG9yIikKLy8jcHJhZ21hIEdDQyB0YXJnZXQoImF2eCxhdngyLGZtYSIpCgovLyNkZWZpbmUgTGViYWNoCiNkZWZpbmUgT0ZGTElORQoKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KLy8jaW5jbHVkZTxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KLy8jaW5jbHVkZTxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdXNpbmcgbmFtZXNwYWNlIGNocm9ubzsKLy91c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsKCiNkZWZpbmUgZmFzdGlvKCkgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWx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7CiAgICAgICAgaW50IHYgPSBxLnRvcCgpLmZmOwogICAgICAgIGludCBkX3YgPSBxLnRvcCgpLnNzOwogICAgICAgIHEucG9wKCk7CiAgICAgICAgaWYoZF92ICE9IGRbdl0pIGNvbnRpbnVlOwoKICAgICAgICBmb3IoYXV0byBlZGdlOiBncmFwaFt2XSl7CiAgICAgICAgICAgIGludCB2MSA9IGVkZ2UuZmY7CiAgICAgICAgICAgIGludCBkX3YxID0gZWRnZS5zczsKCiAgICAgICAgICAgIGlmKGRbdl0gKyBkX3YxIDwgZFt2MV0pewogICAgICAgICAgICAgICAgZFt2MV0gPSBkW3ZdICsgZF92MTsKICAgICAgICAgICAgICAgIHEucHVzaCh7djEsIGRbdjFdfSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCnZvaWQgc29sdmUoKSB7CiAgICBkaXMocyk7CiAgICBpZihkW3QxXSA+IGRbdDJdKXsKICAgICAgICBvcHRpX3QgPSB0MjsKICAgICAgICBhbnMgKz0gZFt0Ml07CiAgICAgICAgZC5yZXNpemUobiszLCBJTkYpOwogICAgICAgIGRpcyhvcHRpX3QpOwogICAgICAgIGFucyArPSBkW3QxXTsKICAgIH0gZWxzZSB7CiAgICAgICAgb3B0aV90ID0gdDE7CiAgICAgICAgYW5zICs9IGRbdDFdOwogICAgICAgIGQucmVzaXplKG4rMywgSU5GKTsKICAgICAgICBkaXMob3B0aV90KTsKICAgICAgICBhbnMgKz0gZFt0Ml07CiAgICB9CgogICAgY291dCA8PCBhbnM7Cgp9CgoKLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSovCgp2b2lkIENvbWJpbmF0aW9uX3N5c3RlbSgpewogICAgUmVhZCgpOwogICAgc29sdmUoKTsK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