https://www.lydsy.com/JudgeOnline/problem.php?id=1880
https://www.luogu.org/problemnew/show/P2149
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v,w;
int ans,cnt,flag,temp,sum;
int x,y,x2,y2,dis[5][N],dp[N];
bool vis[N],col[N];
char str;
struct node{
int v,w;
node(){};
node(int _v,int _w):v(_v),w(_w){}
};
vector<node>G[N],H[N];
void SPFA(int x,int* dis){
queue<int>q;
while (!q.empty()) q.pop();
for(int i=1;i<=n;i++)dis[i]=INF;
dis[x]=0;
q.push(x);
memset(vis,0,sizeof(vis));
while(!q.empty()){
int u=q.front();
q.pop();
vis[u]=0;
for(int i=0,j=G[u].size();i<j;i++){
int v=G[u][i].v;
if(dis[v]>dis[u]+G[u][i].w){
dis[v]=dis[u]+G[u][i].w;
if(!vis[v]){
vis[v]=1;
q.push(v);
}
}
}
}
}
int dfs(int u){
if (dp[u]) return dp[u];
for(int i=0,j=H[u].size();i<j;i++){
int v=H[u][i].v,w=H[u][i].w;
dp[u]=max(dp[u],dfs(v)+w); //核心,深搜算u前驱的答案。
}
return dp[u];
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
//scanf("%d",&t);
//while(t--){
scanf("%d%d",&n,&m);
scanf("%d%d%d%d",&x,&y,&x2,&y2);
for(int i=1;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
G[u].push_back({v,w});
G[v].push_back({u,w});
}
SPFA(x,dis[1]);
SPFA(x2,dis[2]);
SPFA(y,dis[3]);
SPFA(y2,dis[4]);
for(int i=1;i<=n;i++){
for(int j=0,k=G[i].size();j<k;j++){
int u=i,v=G[i][j].v,w=G[i][j].w;
if (dis[1][u]+w+dis[3][v]==dis[1][y]){
if (dis[2][u]+w+dis[4][v]==dis[2][y2]) ++cnt,H[u].push_back({v,w}),col[u]=col[v]=1;
if (dis[2][v]+w+dis[4][u]==dis[2][y2]) ++cnt,H[v].push_back({u,w}),col[u]=col[v]=1;
}
}
}
for(int i=1;i<=n;++i)if(col[i]&&!dp[i])dfs(i);
for(int i=1;i<=n;++i)ans=max(ans,dp[i]);
printf("%d\n",ans);
//}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}
/*
9 12
1 9 7 3
1 2 1
1 4 1
7 4 1
7 8 1
9 8 1
6 9 1
3 2 1
3 6 1
5 2 1
5 4 1
5 6 1
5 8 1
*/