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 <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int N,M;
ll dp[114514]={0};
void shortestPath(const Graph &g, int s,
				  vector<Weight> &dist, vector<int> &prev) {
	int n = g.size();
	dist.assign(n, INF); dist[s] = 0;
	rep(i,n)dp[i]=0;
	prev.assign(n, -1);
	dp[s]=1;
	priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
	Edge hoge={-2, s, 0};
	for (Q.push(hoge); !Q.empty(); ) {
		Edge e = Q.top(); Q.pop();
		if (prev[e.dst] != -1) continue;
		prev[e.dst] = e.src;
		FOR(f,g[e.dst]){
			if (dist[f->dst] > e.weight+f->weight) {
			 dist[f->dst] = e.weight+f->weight;
				dp[f->dst] =dp[f->src];
				Edge fuga={f->src, f->dst, e.weight+f->weight};
				Q.push(fuga);
			}else if(dist[f->dst] == e.weight+f->weight){
				dp[f->dst]=(dp[f->dst]+dp[f->src])%MOD;
			}
		}
	}
}

int main(){
	cin>>N>>M;
	int S,T;
	cin>>S>>T;S--;T--;
	Graph Gph(N);
	vector<pair<pii,ll> > data;
	for(int i=0;i<M;i++){
		int u,v;
		Weight d;
		cin>>u>>v>>d;u--;v--;
		Edge hen={u,v,d};
		Gph[u].pb(hen);
		Edge gen={v,u,d};
		Gph[v].pb(gen);
		data.pb(mp(mp(u,v),d));
	}
	vector<Weight> ans,ans2;
	vi hoge;
	shortestPath(Gph,S,ans,hoge);
	ll kyori=ans[T];
	ll dp2[114514];
	for(int i=0;i<N;i++){
		dp2[i]=dp[i];
	}
	shortestPath(Gph,T,ans2,hoge);
	ll Ans=0;
	for(int i=0;i<M;i++){
		pii za = data[i].first;
		int x = za.first,y = za.second;
		if(ans[x]>ans[y])swap(x,y);
		//cout<<ans[x] + ans2[y] + data[i].second<<endl;
		if((ll)(2*ans[x])<kyori && kyori<(ll)(2*(ans[x]+data[i].second)) && (ans[x] + ans2[y] + data[i].second) == kyori){
			Ans = (Ans+(dp2[x]*dp[y])%MOD)%MOD;
			//cout<<kyori<<" "<<data[i].second<<endl;
		}
	}
	//cout<<Ans<<endl;
	for(int i=0;i<N;i++){
		if((ll)2*ans[i] == kyori){
			Ans = (Ans+(dp[i]*dp2[i])%MOD)%MOD;
		}
	}	
	//rep(i,N)cout<<dp2[i]<<" ";
	//cout<<endl;
	//cout<<kyori<<endl;
	Ans = ((dp[S]*dp[S])%MOD + MOD - Ans)%MOD;
	cout<<Ans<<endl;
}