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 <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head

int x,s,t,m,n,k,res;
int a[501000] = {};
int b[501000] = {};
int c[501000] = {};
vector<PII> g[500010];
queue<int> que2;
ll dp1[100010]={}, dp2[100010]={};
//string s;
vector<ll> dijkstra(ll n, vector<pair<ll,ll> >* G, ll s) {
    vector<ll> d(n, 1ll<<55); d[s] = 0;
    priority_queue<pair<ll, ll> > que;
    que.push(make_pair(0ll, s));
    while (!que.empty()) {
			auto p = que.top();que.pop();
			ll prov_cost = p.first;
			ll src = p.second;
			if(d[src]<prov_cost) continue;
			rep(i,0,g[src].size()){
				ll dest = g[src][i].first;
				ll weight = g[src][i].second;
				if ((d[dest] > d[src] + weight)){
					d[dest] = d[src] + weight;
					que.push({-d[dest],dest});
				}
			}
		}
    return d;
}

signed main() {
	std::cin >>n>>m>>s>>t;
	s--,t--;
	rep(i,0,m){
		std::cin >> a[i]>>b[i]>>c[i];
		b[i]--,a[i]--;
		g[a[i]].pb(mp(b[i], c[i]));
		g[b[i]].pb(mp(a[i], c[i]));
	}
	vector<ll> d = dijkstra(n, g, s);
	vector<PII> vec;
	rep(i,0, n) vec.pb({d[i], i});
	sort(all(vec));
	dp1[s] = 1;
	rep(i,0,n){
		for(auto e : g[vec[i].second]){
			if(d[vec[i].second] + e.second == d[e.first]) {
        dp1[e.first] += dp1[vec[i].second];
				dp1[e.first] %= mod;
      }
		}
	}
	d = dijkstra(n, g, t);
	vec.clear();
	rep(i,0, n) vec.pb({d[i], i});
	sort(all(vec));
	dp2[t] = 1;
	rep(i,0,n){
		for(auto e : g[vec[i].second]){
			if(d[vec[i].second] + e.second == d[e.first]) {
        dp2[e.first] += dp2[vec[i].second];
				dp2[e.first] %= mod;
      }
		}
	}
	res = dp1[t]*dp1[t]+mod*mod;
	rep(i,0,n){
		if( d[i] == d[s]/2){
			res -= dp1[i]*dp1[i]*dp2[i]*dp2[i];
		}
	}
	vector<ll> d1 = dijkstra(n, g, s);
	rep(i,0,m){
		if(d1[a[i]]<d[s]/2 && d[b[i]]<d[s]/2 && d[b[i]]+c[i] == d[a[i]]){
			res -= dp1[a[i]]*dp1[a[i]]*dp2[b[i]]*dp2[b[i]];
		}
		else if (d[a[i]]<d[s]/2 && d1[b[i]]<d[s]/2 && d[a[i]]+c[i] == d[b[i]]){
			res -= dp2[a[i]]*dp2[a[i]]*dp1[b[i]]*dp1[b[i]];
		}
//		std::cout << res << '\n';
	}
	std::cout << res%mod << '\n';
}