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 times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(auto i##0_to = (t), i = decltype(t)(f); i <= i##0_to; i++)
#define uptil(f, t, i)   for(auto i##0_to = (t), i = decltype(t)(f); i <  i##0_to; i++)
#define downto(f, t, i)  for(auto i##0_to = decltype(f)(t), i = (f); i >= i##0_to; i--)
#define downtil(f, t, i) for(auto i##0_to = decltype(f)(t), i = (f); i >  i##0_to; i--)
// types
	using LD = long double;
	#define double LD
	#define long long long
	#define int long
	using VB = vector<bool>;   using WB = vector<VB>;
	using VC = vector<char>;   using WC = vector<VC>;
	using VI = vector<int>;    using WI = vector<VI>;
	using VD = vector<double>; using WD = vector<VD>;
	using VS = vector<string>; using WS = vector<VS>;
	using PI = pair<int, int>;
	using TI = tuple<int, int, int>;
	using VPI = vector<PI>;    using WPI = vector<VPI>;

bool debug;
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << '\n'
#define tb << '\t'
#define sp << ' '
#define db(x) if(debug) cerr << #x << " = " << (x) << ", "
#define dbg(x) if(debug) cerr << #x << " = " << (x) ln

void solve();

signed main(signed argc, char *argv[]) {
	#ifdef EBUG
		debug = true;
	#elif defined(ONLINE_JUDGE)
		debug = false;
	#else
		debug = argc >= 2;
	#endif
	if(!debug) {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);

	solve();

	return 0;
}

/******************************* basic library ********************************/
// IO
	template<class T>
	istream& operator>>(istream& s, vector<T>& v) {
		for(auto&& p : v) s >> p; return s;
	}
	template<class T>
	ostream& operator<<(ostream& s, vector<T> v) {
		int i = 0;
		for(const auto& p : v) s << (i++?" ":"") << p;
		return s;
	}
	template<class T>
	ostream& operator<<(ostream& s, vector<vector<T>> w) {
		for(const auto& v : w) {
			int i = 0;
			for(const auto& p : v) s << (i++?" ":"") << p;
			s ln;
		}
		return s;
	}
	template<class T> T& RD(T& t) { cin >> t; return t; }
	template<class T, class... A> T RD(A... a) { T t(a...); cin >> t; return t; }
// container
	#define all(v) (v).begin(), (v).end()
	template<class T> T max(const pair<T, T>& p) { return max(p.first, p.second); }
	template<class T> T min(const pair<T, T>& p) { return min(p.first, p.second); }
// other
	#define b_max(x, y) x = max(x, y)
	#define b_min(x, y) x = min(x, y)
	inline LD AC(LD d) { return d ? d : 0; }
constexpr long INF = 1LL << 60;
constexpr long MOD = 1000000007; // 998244353;

/****************************** optional library ******************************/


/************************************ main ************************************/

void solve() {
	int N, M, S, T; cin >> N >> M >> S >> T; --S; --T;
	vector<map<int, int>> path(N);
	times(M, i) {
	    int U, V, D; cin >> U >> V >> D;
	    path[U-1][V-1] = path[V-1][U-1] = D;
	}
	vector<int> costs_S(N, LLONG_MAX), costs_T(N, LLONG_MAX), count_S(N+1, 0), count_T(N+1, 0);
	{/* <sr.g.djk> */
		// NOT_VERIFIED
		priority_queue<TI, vector<TI>, greater<TI>> pq;
		pq.push(TI{0, S, N});
		count_S[S] = 1;
		while(!pq.empty()) {
			int i; int before; int c;
			tie(c, i, before) = pq.top(); pq.pop();
			if(costs_S[i] >= c) (count_S[i] += count_S[before]) %= MOD;
			if(costs_S[i] > c) {
				costs_S[i] = c;
				for(const auto& p : path[i]) { /* 1e14: {index, cost} */
					int j = p.first, d = c + p.second;
					if(costs_S[j] >= d) pq.push(TI{d, j, i});
				}
			}
		}
	}/* </sr.g.djk> */
	{/* <sr.g.djk> */
		// NOT_VERIFIED
		priority_queue<TI, vector<TI>, greater<TI>> pq;
		pq.push(TI{0, T, N});
		count_T[T] = 1;
		while(!pq.empty()) {
			int i; int before; int c;
			tie(c, i, before) = pq.top(); pq.pop();
			if(costs_T[i] >= c) (count_T[i] += count_T[before]) %= MOD;
			if(costs_T[i] > c) {
				costs_T[i] = c;
				for(const auto& p : path[i]) { /* 1e14: {index, cost} */
					int j = p.first, d = c + p.second;
					if(costs_T[j] >= d) pq.push(TI{d, j, i});
				}
			}
		}
	}/* </sr.g.djk> */

	dbg(count_S); dbg(count_T);
	VI& costs_s = costs_S, costs_t = costs_T, num_s = count_S, num_t = count_T;
	int ans = num_s[T] * num_s[T] % MOD, c = costs_s[T];

	times(N, i) {
		if(costs_s[i] * 2 == c && costs_t[i] * 2 == c) (ans -= num_s[i] * num_t[i] % MOD * num_s[i] % MOD * num_t[i]) %= MOD;
	}
	times(N, i) for(auto& p : path[i]) {
		int j = p.first;
		if(costs_s[i] * 2 < c && costs_t[j] * 2 < c && costs_s[i] + costs_t[j] + p.second == c)
			(ans -= num_s[i] * num_t[j] % MOD * num_s[i] % MOD * num_t[j]) %= MOD;
	}
	cout << ans ln;

/*
	VB mv(N);
	int cst = costs_S[T], s = count_S[T];
	times(N, i) {
		if(cst % 2 == 0 && costs_S[i] == cst / 2 && costs_T[i] == cst / 2) {
			mv[i] = true;
			//(s += count_S[i] * count_T[i]) %= MOD;
		}
	}
	times(N, i) for(const auto& p : path[i]) {
		int j = p.first;
		if(not mv[i] && not mv[j] && costs_S[i] + costs_T[j] + p.second == cst &&
			costs_S[i] <= cst / 2 && costs_T[j] <= cst / 2) {
			//(s += count_S[i] * count_T[j]) %= MOD;
		}
	}
	dbg(s);
	int ans = s * s % MOD;
	times(N, i) {
		if(mv[i]) {
			(ans -= count_S[i] * count_T[i] % MOD * count_S[i] % MOD * count_T[i]) %= MOD;
			if(ans < 0) ans += MOD;
			db(i); dbg(ans);
		}
	}
	times(N, i) for(const auto& p : path[i]) {
		int j = p.first;
		if(not mv[i] && not mv[j] && costs_S[i] + costs_T[j] + p.second == cst &&
			costs_S[i] * 2 < cst && costs_T[j] * 2 < cst) {
			db(i); db(j); dbg(ans);
			(ans -= count_S[i] * count_T[j] % MOD * count_S[i] % MOD * count_T[j]) %= MOD;
			if(ans < 0) ans += MOD;
		}
	}
	cout << ans % MOD ln;
*/
}