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 Perl (v5.18.2) (judge verdict: Time Limit Exceeded)

$mod=1000000007;$maxD=$mod*100000;
($N,$M) =split(" ",<STDIN>);
($S,$T) =split(" ",<STDIN>);
$S--;$T--;

@CC=();$CC[$N-1]=[];
foreach(0..$N-1) { @{$CC[$_]}=(); }
foreach (1..$M) {
	$l=<STDIN>;
	$j=index($l," ");
	$U=int($l)-1;
	$V=int(substr($l,$j                ))-1;
	$D=int(substr($l,index($l," ",$j+1)))*2;
	push @{$CC[$U]},($V,$D);
	push @{$CC[$V]},($U,$D);
}

@DS=();@DT=();
foreach(0..$N-1) { $DS[$_]=$maxD;$DT[$_]=$maxD; }
$DS[$S]=0;$DT[$T]=0;

@OS=();
@PK=();$PK[$N-1]=0;
@FS=();$FS[$N-1]=0;$FS[$S]=1;
@FT=();$FT[$N-1]=0;$FT[$T]=1;

@QS1=();$QS1[$M-1]=0;$QS1[0]=$S;
@QS2=();$QS2[$M-1]=0;$QS2[0]=0;
$QSC=0;
@QT1=();$QT1[$M-1]=0;$QT1[0]=$T;
@QT2=();$QT2[$M-1]=0;$QT2[0]=0;
$QTC=0;

$pd=$QS2[0];
$rd=$QT2[0];
$f=1;
while ($f && $QSC>=0 && $QTC>=0) {
	if ( $pd<=$rd ) {
		#from S
		while($QSC>=0 && $pd==$QS2[0]) {
			#binary heap deque >
			$p=$QS1[0];
			$q=$QS1[$QSC];
			$d=$QS2[$QSC];
			$QSC--;
			#if ($QSC>=0) {
				$j=0;$i=1;
				while ( $i<=$QSC ) {
					#$i=$i+1 if ($i<$QSC && $QS2[$i]>$QS2[$i+1] );
					$dd=$QS2[$i];
					if ($i<$QSC && $dd>$QS2[$i+1]) {
						$i++;
						$dd=$QS2[$i];
					}
					last if ( $dd >= $d );
					$QS1[$j]=$QS1[$i];
					$QS2[$j]=$dd;
					$j=$i;
					$i=$j*2+1;
				}
				$QS1[$j]=$q;
				$QS2[$j]=$d;
			#}
			#< binary heap deque
			if ($PK[$p]==2) { $f=0; next; }
			if ($pd>$DS[$p]) { next; }
			$a=$CC[$p];
			for($x=$#{$a}-1;$x>=0;$x-=2) {
				($q,$d)=@{$a}[$x,$x+1];$d+=$pd;
				if ($DS[$q]>$d) {
					$DS[$q]=$d;
					$FS[$q]=$FS[$p];
					#binary heap enque >
					$j=$QSC+1;
					while ( $j>0 ) {
						$i=int(($j-1)/2);
						last if ( $QS2[$i]<=$d );
						$QS1[$j]=$QS1[$i];
						$QS2[$j]=$QS2[$i];
						$j=$i;
					}
					$QS1[$j]=$q;
					$QS2[$j]=$d;
					$QSC++;
					#< binary heap enque
				} elsif ( $DS[$q]==$d ) {
					$FS[$q]+=$FS[$p];
				}
			}
			$PK[$p]=1;
			push @OS,$p;
		}
		$pd=$QS2[0];
	} else {
		#from T
		while($QTC>=0 && $rd==$QT2[0]) {
			#binary heap deque >
			$r=$QT1[0];
			$q=$QT1[$QTC];
			$d=$QT2[$QTC];
			$QTC--;
			#if ($QTC>=0) {
				$j=0;$i=1;
				while ( $i<=$QTC ) {
					#$i=$i+1 if ($i<$QTC && ( $QT2[$i]>$QT2[$i+1] ));
					$dd=$QT2[$i];
					if ($i<$QTC && $dd>$QT2[$i+1]) {
						$i++;
						$dd=$QT2[$i];
					}
					last if ( $dd >= $d );
					$QT1[$j]=$QT1[$i];
					$QT2[$j]=$dd;
					$j=$i;
					$i=$j*2+1;
				}
				$QT1[$j]=$q;
				$QT2[$j]=$d;
			#}
			#< binary heap deque
			if ($PK[$r]==1) { $f=0; next; }
			if ($rd>$DT[$r]) { next; }
			$a=$CC[$r];
			for($x=$#{$a}-1;$x>=0;$x-=2) {
				($q,$d)=@{$a}[$x,$x+1];$d+=$rd;
				if ($DT[$q]>$d) {
					$DT[$q]=$d;
					$FT[$q]=$FT[$r];
					#binary heap enque >
					$j=$QTC+1;
					while ( $j>0 ) {
						$i=int(($j-1)/2);
						last if ( $QT2[$i]<=$d );
						$QT1[$j]=$QT1[$i];
						$QT2[$j]=$QT2[$i];
						$j=$i;
					}
					$QT1[$j]=$q;
					$QT2[$j]=$d;
					$QTC++;
					#< binary heap enque
				} elsif ( $DT[$q]==$d ) {
					$FT[$q]+=$FT[$r];
				}
			}
			$PK[$r]=2;
		}
		$rd=$QT2[0];
	}
}

@OS2=();
$da=$pd+$rd;
foreach $p (@OS) {
	if ( $DS[$p]+$DT[$p] < $da ) {
		$da = $DS[$p]+$DT[$p];
		@OS2=($p);
	} elsif ( $DS[$p]+$DT[$p] == $da ) {
		push @OS2,$p;
	}
}
$coltime=$da/2;

$t=0;$s=0;
foreach $p (@OS2) {
	if ($DS[$p] == $coltime ) {
		$v=($FS[$p]*$FT[$p])%$mod;
		$s=($s+$v)%$mod;
		$t=($t+$v*$v)%$mod;
	} else {
		$a=$CC[$p];
		for($x=$#{$a}-1;$x>=0;$x-=2) {
			$q=${$a}[$x];
			next if ( $PK[$q]!=2 );
			next if ( $DS[$q]+$DT[$q]!=$da );
			next if ( $DS[$p]+${$a}[$x+1]!=$DS[$q]);
			$v=($FS[$p]*$FT[$q])%$mod;
			$s=($s+$v)%$mod;
			$t=($t+$v*$v)%$mod;
		}
	}
}

$t=($s*$s+$mod-$t)%$mod;
print $t;