// https://o...content-available-to-author-only...i.info/problem/lhphcm_bus
#include <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define fi first
#define se second
using namespace std;
const int maxn = 2e5+3;
int n, m, s, t, news, newt;
ll dist3[maxn][3], dist1[maxn], dist2[maxn];
vector<pii> graph[maxn];
void dijkstra(int src, ll dist[]) {
for (int i = 1; i <= n; i++) dist[i] = LLONG_MAX;
bitset<maxn> visited = 0;
priority_queue<pii> pq; pq.push({0, src});
dist[src] = 0;
while (!pq.empty()) {
int u = pq.top().second; pq.pop();
if (visited[u]) continue;
visited[u] = true;
for (int i = 0, v, w; i < graph[u].size(); i++) {
v = graph[u][i].first, w = graph[u][i].second; if (v == u) continue;
if (dist[v] <= dist[u] + w) continue;
dist[v] = dist[u] + w;
pq.push({-dist[v], v});
}
}
}
struct Edge {
int v; ll w; int state;
Edge (int V, ll W, int S = 0) {v = V; w = W; state = S;}
bool operator < (const Edge &b) {return w < b.w || (w == b.w && state < b.state);}
};
struct comp {
bool operator () (const Edge &a, const Edge &b)
{return a.w > b.w || (a.w == b.w && a.state > b.state);}
};
void dijkstra2() {
for (int i = 1; i <= n; i++) dist3[i][0] = dist3[i][1] = dist3[i][2] = LLONG_MAX;
priority_queue<Edge, vector<Edge>, comp> pq; pq.push(Edge(news, 0, 0));
dist3[news][1] = dist3[news][2] = 0;
while (!pq.empty()) {
int u = pq.top().v, state = pq.top().state;
ll w = pq.top().w; pq.pop();
if (dist3[u][state] <= w) continue;
dist3[u][state] = w;
if (u == newt) return;
for (int i = 0, v, ww; i < graph[u].size(); i++) {
v = graph[u][i].fi, ww = graph[u][i].se; if (v == u) continue;
if (state <= 1 && min(dist1[u]+dist2[v], dist2[u]+dist1[v])+ww == dist1[t]) // on a shortest path
{if (dist3[v][1] > w) pq.push(Edge(v, w, 1));}
else if (dist3[v][(state>=1)<<1] > w+ww)
pq.push(Edge(v, w+ww, (state>=1)<<1));
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> s >> t >> news >> newt;
int a, b, c;
while (m--) {
cin >> a >> b >> c;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
dijkstra(s, dist1); dijkstra(t, dist2);
// for (int i = 1; i <= n; i++) cout << dist1[i] << ' '; cout << '\n';
// for (int i = 1; i <= n; i++) cout << dist2[i] << ' '; cout << '\n';
dijkstra2();
cout << min(dist3[newt][0], min(dist3[newt][1], dist3[newt][2])) << '\n';
return 0;
}
Ly8gaHR0cHM6Ly9vLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5pLmluZm8vcHJvYmxlbS9saHBoY21fYnVzCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIHBpaSBwYWlyPGludCwgaW50PgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgbWF4biA9IDJlNSszOwoKaW50IG4sIG0sIHMsIHQsIG5ld3MsIG5ld3Q7CmxsIGRpc3QzW21heG5dWzNdLCBkaXN0MVttYXhuXSwgZGlzdDJbbWF4bl07CnZlY3RvcjxwaWk+IGdyYXBoW21heG5dOwoKdm9pZCBkaWprc3RyYShpbnQgc3JjLCBsbCBkaXN0W10pIHsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgZGlzdFtpXSA9IExMT05HX01BWDsKICAgIGJpdHNldDxtYXhuPiB2aXNpdGVkID0gMDsKICAgIHByaW9yaXR5X3F1ZXVlPHBpaT4gcHE7IHBxLnB1c2goezAsIHNyY30pOwogICAgZGlzdFtzcmNdID0gMDsKICAgIHdoaWxlICghcHEuZW1wdHkoKSkgewogICAgICAgIGludCB1ID0gcHEudG9wKCkuc2Vjb25kOyBwcS5wb3AoKTsKICAgICAgICBpZiAodmlzaXRlZFt1XSkgY29udGludWU7CiAgICAgICAgdmlzaXRl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