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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007

typedef struct edge{ll s,g,c;}E;
int edgehikaku(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}


//プラキュー（二分ヒープ）（優先度変更ありバージョン）
ll heapN,heap[1<<20],heapinv[1<<20];
int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
void PQchange(int n);
void heap_utod(int n){
	if(2*n>heapN)return;
	int rflag=(2*n+1<=heapN)&&(PQhikaku(2*n,2*n+1));
	if(PQhikaku(n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heapinv[heap[n]]=n;
		heapinv[heap[2*n+rflag]]=2*n+rflag;	
		heap_utod(2*n+rflag);
	}
}
void heap_dtou(int n){
	if(n==1||PQhikaku(n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heapinv[heap[n]]=n;
	heapinv[heap[n/2]]=n/2;
	heap_dtou(n/2);
}
ll PQpop(){
	ll rr=heap[1];
	heapinv[heap[1]]=0;
	heap[1]=heap[heapN--];
	heapinv[heap[1]]=1;
	heap_utod(1);
	return rr;
}
void PQpush(ll n){
	heap[++heapN]=n;
	heapinv[heap[heapN]]=heapN;
	heap_dtou(heapN);
}



//頂点数、スタート、辺の情報、辺の数を引いて最短距離を返す
//辺は有向辺なので、無向なら両方の向きを入れること
//O((E+V)logV)
ll daikusutorappp[100010];
ll daikusutora222[100010];//追加
void daikusutora2(ll n,ll s,E*e,ll ecnt){
	qsort(e,ecnt,sizeof(E),edgehikaku);

	ll*es=(ll*)malloc(n*sizeof(ll));
	es[0]=0;
	ll t=0;
	rep(i,1,n){
		while(t<ecnt&&e[t].s<i)t++;
		es[i]=t;
	}
	rep(i,0,n)daikusutorappp[i]=i==s?0:INF;
	rep(i,0,n)daikusutora222[i]=i==s?1:0;//追加	
	rep(i,0,n)PQpush(i);
	while(heapN){
		ll mv=PQpop();
		for(ll t=es[mv];e[t].s==mv;t++){
			if(daikusutorappp[e[t].g]>daikusutorappp[mv]+e[t].c){
				daikusutorappp[e[t].g]=daikusutorappp[mv]+e[t].c;
				daikusutora222[e[t].g]=daikusutora222[mv];//追加
				PQchange(e[t].g);
			}else if(daikusutorappp[e[t].g]==daikusutorappp[mv]+e[t].c){//追加
				daikusutora222[e[t].g]+=daikusutora222[mv];//追加
				daikusutora222[e[t].g]%=MOD;
			}
		}
	}
	free(es);
}
int PQhikaku(int i,int j){return daikusutorappp[heap[i]]>daikusutorappp[heap[j]];}
void PQchange(int n){if(heapinv[n])heap_dtou(heapinv[n]);}


ll scost[100010];
ll tcost[100010];
ll scnt[100010];
ll tcnt[100010];
E e[400010];
ll n,m;
int main(){
	scanf("%lld%lld",&n,&m);
	ll s,t;
	scanf("%lld%lld",&s,&t);
	s--,t--;
	rep(i,0,m){
		ll a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		a--,b--;
		e[2*i].s=a;e[2*i+1].s=b;
		e[2*i].g=b;e[2*i+1].g=a;
		e[2*i].c=c;e[2*i+1].c=c;
	}
	daikusutora2(n,s,e,2*m);
	rep(i,0,n){
		scost[i]=daikusutorappp[i];
		scnt[i]=daikusutora222[i];
//		printf("%lld %lld %lld\n",i,scost[i],scnt[i]);
	}
	daikusutora2(n,t,e,2*m);
	rep(i,0,n){
		tcost[i]=daikusutorappp[i];
		tcnt[i]=daikusutora222[i];
//		printf("%lld %lld %lld\n",i,tcost[i],tcnt[i]);
	}
	
	ll d=scost[t];//最短距離
	ll ans=scnt[t]*tcnt[s]%MOD;
	//頂点iで出会う⇔s-i-tが真ん中
	rep(i,0,n)if(scost[i]*2==d)ans=(ans-scnt[i]*tcnt[i]%MOD*tcnt[i]%MOD*scnt[i]%MOD+MOD)%MOD;
	//辺iで出会う⇔両端をx,yとして、s-x-y-tの間が真ん中
	rep(i,0,2*m){
		if(scost[e[i].s]+e[i].c+tcost[e[i].g]==d&&scost[e[i].s]*2<d&&tcost[e[i].g]*2<d){
			ans=(ans-scnt[e[i].s]*tcnt[e[i].g]%MOD+MOD)%MOD;
//			printf("%lld %lld %lld %lld %lld\n",e[i].s,e[i].g,e[i].c,scost[e[i].s],tcost[e[i].g]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}