// Starcraft 2 enjoyer //
#include <bits/stdc++.h>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
#define LSOne(X) ((X) & -(X))
#define int long long
const int N = 2e5 + 5;
const int M = 11;
const int B = 18;
const long long K = 2;
const int LG = 20;
const long long INF = 1e18 + 5;
const int P = 31;
const int MOD = 998244353;
const int nx[] = {0, 1, 0, -1}, ny[] = {-1, 0, 1, 0};
int n, m, s, t, u, v;
long long dis1[N], dis2[N], dis3[4][N];
bool vis[N], vis2[4][N];
vector<pair<int, int>> adj[N];
vector<array<int, 3>> adj2[4][N], edges;
inline void cal(long long *dis, int u)
{
priority_queue<pair<int, int>> pq;
for (int x = 1; x <= n; x++)
{
dis[x] = INF;
vis[x] = 0;
}
dis[u] = 0;
pq.push({0, u});
while (!pq.empty())
{
auto [w, c] = pq.top();
pq.pop();
if (vis[c])
continue;
vis[c] = 1;
for (auto &[i, w] : adj[c])
{
if (dis[i] > dis[c] + w)
{
dis[i] = dis[c] + w;
pq.push({-dis[i], i});
}
}
}
}
inline void cal2(long long dis[4][N], bool vis[4][N], int u)
{
priority_queue<array<int, 3>> pq;
for (int y = 0; y < 4; y++)
{
for (int x = 1; x <= n; x++)
{
dis[y][x] = INF;
vis[y][x] = 0;
}
}
dis[0][u] = 0;
pq.push({0, 0, u});
while (!pq.empty())
{
auto [w, t, c] = pq.top();
pq.pop();
if (vis[t][c])
continue;
// cout << -w << " " << t << " " << c << "\n";
vis[t][c] = 1;
for (auto &[nt, i, w] : adj2[t][c])
{
if (dis[nt][i] > dis[t][c] + w)
{
dis[nt][i] = dis[t][c] + w;
pq.push({-dis[nt][i], nt, i});
}
}
}
// cout << u << "\n";
// for (int x = 1; x <= n; x++)
// {
// cout << dis[3][x] << " ";
// }
// cout << "\n";
}
inline void solve()
{
cin >> n >> m >> s >> t >> u >> v;
for (int x = 0; x < m; x++)
{
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
edges.push_back({a, b, c});
}
cal(dis1, s);
cal(dis2, t);
for (int x = 0; x < m; x++)
{
auto [a, b, c] = edges[x];
adj2[0][a].push_back({0, b, c});
adj2[0][b].push_back({0, a, c});
adj2[3][a].push_back({3, b, c});
adj2[3][b].push_back({3, a, c});
if (dis1[a] + dis2[b] + c == dis1[t])
{
// cout << a << " " << b << "num1\n";
adj2[1][a].push_back({1, b, 0});
adj2[2][b].push_back({2, a, 0});
}
if (dis1[b] + dis2[a] + c == dis1[t])
{
// cout << a << " " << b << "num2\n";
adj2[2][a].push_back({2, b, 0});
adj2[1][b].push_back({1, a, 0});
}
}
for (int x = 1; x <= n; x++)
{
adj2[0][x].push_back({1, x, 0});
adj2[0][x].push_back({2, x, 0});
adj2[1][x].push_back({3, x, 0});
adj2[2][x].push_back({3, x, 0});
}
cal2(dis3, vis2, u);
cout << dis3[3][v] << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
for (int x = 1; x <= t; x++)
{
solve();
}
return 0;
}