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 <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000010000;

ll kai[100010];
ll bit[700010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 700005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

ll N, M;
ll S, T;
ll U[200010], V[200010];
struct edge { ll to, cost; };
vector<edge> E[100010];
ll ans;

ll d[100010][2];
ll sum[100010][2];
map<ll, ll> mp;
bool path[100010];

void dij(ll start, ll dir) {
	priority_queue<P, vector<P>, greater<P>> que;
	rep(i, N + 1) d[i][dir] = INF;
	d[start][dir] = 0;
	sum[start][dir] = 1;
	que.push(P( 0, start));
	while (que.size()) {
		P p = que.top(); que.pop();
		if (p.f > d[p.s][dir]) continue;
		for (edge e : E[p.s]) {
			if (d[e.to][dir] > d[p.s][dir] + e.cost) {
				d[e.to][dir] = d[p.s][dir] + e.cost;
				sum[e.to][dir] = sum[p.s][dir];
				que.push(P( d[e.to][dir], e.to ));
			}
			else if (d[e.to][dir] == d[p.s][dir] + e.cost) {
				sum[e.to][dir] += sum[p.s][dir];
			}
		}
	}
}

void dfs(ll now) {
	path[now] = true;
	for (edge e : E[now]) {
		if (d[now][0] - e.cost == d[e.to][0] && !path[e.to]) {
			dfs(e.to);
		}
	}
}

void solve() {
	cin >> N >> M;
	cin >> S >> T;
	rep(i, M) {
		ll D;
		cin >> U[i] >> V[i] >> D;
		E[U[i]].pb(edge{ V[i], D });
		E[V[i]].pb(edge{ U[i], D });
	}
	dij(S, 0);
	dij(T, 1);

	for (int i = 1; i <= N; i++) {
		if (d[T][0] % 2 == 0) {
			if (d[i][0] < d[T][0] / 2) {
				mp[i] = 1;
			}
			if (d[i][1] < d[T][0] / 2) {
				mp[i] = 2;
			}
		}
		else {
			if (d[i][0] <= d[T][0] / 2) {
				mp[i] = 1;
			}
			if (d[i][1] <= d[T][0] / 2) {
				mp[i] = 2;
			}
		}
	}

	dfs(T);

	if (d[T][0] % 2 == 0) {
		for (int i = 1; i <= N; i++) {
			if (d[i][0] * 2 == d[T][0] && path[i]) {
				ans += sum[i][0] * sum[i][1];
			}
		}
	}
	
	rep(i, M) {
		ll a = U[i], b = V[i];
		if (mp[a] + mp[b] == 3 && path[a] && path[b]) {
			if (mp[a] == 1) {
				ans += sum[a][0] * sum[b][1];
			}
			else {
				ans += sum[a][1] * sum[b][0];
			}
		}
	}

	ans = sum[T][0] * sum[S][1] - ans;
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}