Problem:
Score : 700 points

Problem Statement

We have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki.

The i-th edge connects Vertex U_i and Vertex V_i.
The time it takes to traverse this edge is D_i minutes, regardless of direction and who traverses the edge (Takahashi or Aoki).

Takahashi departs Vertex S and Aoki departs Vertex T at the same time. Takahashi travels to Vertex T and Aoki travels to Vertex S, both in the shortest time possible.
Find the number of the pairs of ways for Takahashi and Aoki to choose their shortest paths such that they never meet (at a vertex or on an edge) during the travel, modulo 10^9 + 7.

Constraints

1 \leq N \leq 100 000

1 \leq M \leq 200 000

1 \leq S, T \leq N

S \neq T

1 \leq U_i, V_i \leq N (1 \leq i \leq M)

1 \leq D_i \leq 10^9 (1 \leq i \leq M)

If i \neq j, then (U_i, V_i) \neq (U_j, V_j) and (U_i, V_i) \neq (V_j, U_j).

U_i \neq V_i (1 \leq i \leq M)

D_i are integers.

The given graph is connected.

Input

Input is given from Standard Input in the following format:

N M
S T
U_1 V_1 D_1
U_2 V_2 D_2
:
U_M V_M D_M

Output

Print the answer.

Sample Input 1

4 4
1 3
1 2 1
2 3 1
3 4 1
4 1 1

Sample Output 1

2

There are two ways to choose shortest paths that satisfies the condition:

Takahashi chooses the path 1 \rightarrow 2 \rightarrow 3, and Aoki chooses the path 3 \rightarrow 4 \rightarrow 1.

Takahashi chooses the path 1 \rightarrow 4 \rightarrow 3, and Aoki chooses the path 3 \rightarrow 2 \rightarrow 1.

Sample Input 2

3 3
1 3
1 2 1
2 3 1
3 1 2

Sample Output 2

2

Sample Input 3

3 3
1 3
1 2 1
2 3 1
3 1 2

Sample Output 3

2

Sample Input 4

8 13
4 2
7 3 9
6 2 3
1 6 4
7 6 9
3 8 9
1 2 2
2 8 12
8 6 9
2 5 5
4 2 18
5 3 7
5 1 515371567
4 8 6

Sample Output 4

6

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll MOD=1e+9+7;
int N,M;
vpint adj[100000];
ll d[2][100000];
int color[2][100000];
vint p[2][100000];
int dp[2][100000]={0};
void dijkstra(int s,int st){//st:0 前から st:1 後ろから
	priority_queue<pint> PQ;
	rep(i,N){
		d[st][i]=INFl;
		color[st][i]=0;
	}
	d[st][s]=0;
	dp[st][s]=1;
	color[st][s]=1;
	p[st][s].push_back(-1);
	PQ.push(mp(0,s));
	while(!PQ.empty()){
		pint f=PQ.top();
		PQ.pop();
		int u=f.second;
		color[st][u]=2;
		if(d[st][u]< -f.first) continue;
		rep(j,adj[u].size()){
			int v=adj[u][j].first;
			if(color[st][v]==2) continue;
			if(d[st][v]>d[st][u]+adj[u][j].second){
				d[st][v]=d[st][u]+adj[u][j].second;
				PQ.push(mp(-d[st][v],v));
				color[st][v]=1;
				p[st][v].clear();
				p[st][v].push_back(u);
				dp[st][v]=dp[st][u];
			}
			else if(d[st][v]==d[st][u]+adj[u][j].second){
				dp[st][v]+=dp[st][u];
				//PQ.push(mp(-d[st][v],v));
				color[st][v]=1;
				//p[st][v].push_back(u);
			}
		}
	}
}
int u[200000],v[200000],cost[200000];
int main(){
	int s,t;
	scan(N);scan(M);scan(s);scan(t);
	s--; t--;
	rep(i,M){
		scan(u[i]);scan(v[i]);scan(cost[i]);
		u[i]--; v[i]--;
		adj[u[i]].push_back(mp(v[i],cost[i]));
		adj[v[i]].push_back(mp(u[i],cost[i]));
	}
	dijkstra(s,0);
	dijkstra(t,1);
	ll mind=d[0][t];
	ll toori=(dp[0][t]%MOD)*(dp[0][t]%MOD)%MOD;
	ll tensum=0;
	ll hensum=0;
	rep(i,N){
		if(d[0][i]==d[1][i]&&d[0][i]*2==mind){
			//tensum+=(p[0][i].size()%MOD)*(p[0][i].size()%MOD)%MOD*((p[1][i].size()%MOD)*(p[1][i].size()%MOD)%MOD)%MOD;
			tensum+=(dp[0][i]%MOD)*(dp[0][i]%MOD)%MOD*((dp[1][i]%MOD)*(dp[1][i]%MOD)%MOD)%MOD;
			tensum%=MOD;
		}
	}
	rep(i,M){
		int v1=u[i],v2=v[i];
		if(d[0][v1]+d[1][v1]!=mind||d[0][v2]+d[1][v2]!=mind) continue;
		if(d[0][v1]+cost[i]==d[0][v2]){
			if(2*d[0][v1]<mind&&2*d[0][v2]>mind){
				//printf("d[v1]:%d d[v2]:%d cost:%d\n",v1+1,v2+1,cost[i]);
				hensum+=(dp[0][v1]%MOD)*(dp[0][v1]%MOD)%MOD*((dp[1][v2]%MOD)*(dp[1][v2]%MOD)%MOD)%MOD;
				hensum%=MOD;
			}
		}
		else if(d[0][v2]+cost[i]==d[0][v1]){
			if(2*d[0][v2]<mind&&2*d[0][v1]>mind){
				//printf("d[v1]:%d d[v2]:%d cost:%d\n",v1+1,v2+1,cost[i]);
				hensum+=(dp[0][v2]%MOD)*(dp[0][v2]%MOD)%MOD*((dp[1][v1]%MOD)*(dp[1][v1]%MOD)%MOD)%MOD;
				hensum%=MOD;
			}
		}
	}
	//printf("sosu:%lld tensum:%lld hensum:%lld\n",toori,tensum,hensum);
	toori-=(tensum+hensum)%MOD;
	if(toori<0) toori+=MOD;
	prin(toori);
	return 0;
}