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)

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

using P = pair<int, int>;

int N, M;
int S, T;
vector<P> link[200001];

const int O = 1000000007;

int dik[200001];
bool used[200001];

vector<P> route[200001];
vector<P> inv_route[200001];
int link_count[200001];
int inv_link_count[200001];

int add(int a, int b)
{
	return (a + b) % O;
}

int sub(int a, int b)
{
	return (a + O - b) % O;
}

int mul(int a, int b)
{
	return (a * b) % O;
}

signed main()
{
	cin >> N >> M;
	cin >> S >> T;
	REP(i, M)
	{
		int u, v, d;
		cin >> u >> v >> d;
		link[u].push_back(P(v, d));
		link[v].push_back(P(u, d));
	}

	REP(i, N + 1) dik[i] = INT_MAX;
	dik[S] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(P(0, S));
	while (q.size() > 0)
	{
		int d, p;
		tie(d, p) = q.top();
		q.pop();
		if (used[p]) continue;
		used[p] = true;
		for (P l : link[p])
		{
			int new_len = d + l.second;
			if (dik[l.first] == new_len)
			{
				inv_route[l.first].push_back(P(p, l.second));
			}
			if (dik[l.first] > new_len)
			{
				dik[l.first] = new_len;
				inv_route[l.first].clear();
				inv_route[l.first].push_back(P(p, l.second));
				if (l.first != T)
				{
					q.push(P(new_len, l.first));
				}
			}
		}
	}

	int max_len = dik[T];

	memset(used, 0, sizeof(used));
	q.push(P(0, T));
	inv_link_count[T] = 1;
	while (!q.empty())
	{
		int d, p;
		tie(d, p) = q.top();
		q.pop();
		if (used[p]) continue;
		used[p] = true;
		for (P r : inv_route[p])
		{
			inv_link_count[r.first] = add(inv_link_count[r.first], inv_link_count[p]);
			route[r.first].push_back(P(p, r.second));
			q.push(P(d + r.second, r.first));
		}
	}
	int all_cnt = inv_link_count[S];

	memset(used, 0, sizeof(used));
	q.push(P(0, S));
	link_count[S] = 1;
	while (!q.empty())
	{
		int d, p;
		tie(d, p) = q.top();
		q.pop();
		if (used[p]) continue;
		used[p] = true;
		for (P r : route[p])
		{
			link_count[r.first] = add(link_count[r.first], link_count[p]);
			q.push(P(d + r.second, r.first));
		}
	}

	int sum = 0;
	double half = max_len / 2.0;
	for (int i = 1; i < N + 1; i++)
	{
		if (dik[i] == half) //あやしい
		{
			int a = mul(link_count[i], inv_link_count[i]);
			a = sub(all_cnt, a);
			sum = add(sum, a);
		}
		else if(dik[i] < half)
		{
			for (P l : route[i])
			{
				int d = dik[i] + l.second;
				if (d > half)
				{
					int a = mul(link_count[i], inv_link_count[l.first]);
					a = sub(all_cnt, a);
					sum = add(sum, a);
				}
			}
		}
	}
	cout << sum << endl;;
}