#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> diji(int n, int src, vector<vector<pair<ll, ll>>> &adj) {
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
vector<ll> dists(n + 1, 2e18);
dists[src] = 0;
pq.push({0, src});
while (!pq.empty()) {
ll d = pq.top().first;
ll u = pq.top().second;
pq.pop();
if (dists[u] < d) continue;
for (auto e : adj[u]) {
ll v = e.first;
ll wt = e.second;
if (dists[v] > d + wt) {
dists[v] = d + wt;
pq.push({dists[v], v});
}
}
}
return dists;
}
int main() {
int n, m;
cin >> n >> m;
int s, t, u, k;
cin >> s >> t >> u >> k;
vector<vector<pair<ll, ll>>> adj(n + 1);
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({(ll)b, (ll)c});
adj[b].push_back({(ll)a, (ll)c});
}
vector<ll> dists = diji(n, s, adj);
vector<ll> distt = diji(n, t, adj);
ll minST = dists[t];
vector<vector<ll>> dist(n + 1, vector<ll>(3, 2e18));
priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<pair<ll, pair<int, int>>>> pq;
dist[u][0] = 0;
pq.push({0, {u, 0}});
while (!pq.empty()) {
ll d = pq.top().first;
int curr = pq.top().second.first;
int state = pq.top().second.second;
pq.pop();
if (d > dist[curr][state]) continue;
if (state < 2) {
if (dist[curr][state + 1] > d) {
dist[curr][state + 1] = d;
pq.push({d, {curr, state + 1}});
}
}
for (auto e : adj[curr]) {
ll v = e.first;
ll wt = e.second;
ll cost = wt;
if (state == 1) {
if (dists[curr] + wt + distt[v] == minST) cost = 0;
else continue;
}
if (dist[v][state] > d + cost) {
dist[v][state] = d + cost;
pq.push({dist[v][state], {v, state}});
}
}
}
cout << min({dist[k][0], dist[k][1], dist[k][2]}) << endl;
return 0;
}