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 (Clang 3.8.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

const int MAX_N = 100000, MAX_M = 200000;
int N, M, S, T;
int UA[MAX_M], VA[MAX_M], DA[MAX_M];

struct edge { int to, cost; };
const int MAX_V = MAX_N;
const ll INF = INFLL;


// Vの初期化を忘れない。
int V;
vector<edge> G[MAX_V];
ll d1[MAX_V];
ll d2[MAX_V];
ll p1[MAX_V];
ll p2[MAX_V];

void add_edge(int v, int u, int cost) {
  G[v].push_back((edge){u, cost});
  G[u].push_back((edge){v, cost});
}

void dijkstra(int s, ll* d) {
  fill(d, d+V, INF);
  priority_queue<Pll, vector<Pll>, greater<Pll> > pque;
  d[s] = 0;
  pque.push(Pll(0, s));


  while (!pque.empty()) {
    Pll p = pque.top(); pque.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost; 
        pque.push(Pll(d[v]+ e.cost, e.to));
      }
    }
  }
}


void path_calc(int s, ll* d, ll* p) {
  vector<Pll> vp;
  for (int i = 0; i < N; ++i) {
    vp.push_back(Pll(d[i], i));
  }
  sort(all(vp));

  p[s] = 1;
  for (int i = 1; i < vp.size(); ++i) {
    int v = vp[i].sc;
    for (int j = 0; j < G[v].size(); ++j) {
      int u = G[v][j].to, cost = G[v][j].cost;
      if (d[v] != d[u] + cost) continue;
      p[v] += p[u];
      p[v] %= MOD;
    }
  }
}


int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);

  cin >> N >> M >> S >> T;
  --S; --T;
  rep(i, M) {
    cin >> UA[i] >> VA[i] >> DA[i];
    --UA[i]; --VA[i];
  }
  V = N;

  rep(i, M) {
    add_edge(UA[i], VA[i], DA[i]);
  }

  dijkstra(S, d1);
  dijkstra(T, d2);
  ll mi_cost = d1[T];

  path_calc(S, d1, p1);
  path_calc(T, d2, p2);

  ll ans = 0;
  ans = mod(p1[T]*(p1[T]-1), MOD);
  vector<int> half_point;
  for (int i = 0; i < N; ++i) {
    if (d1[i]*2 == mi_cost && d2[i]*2 == mi_cost) half_point.push_back(i); 
  }
  for (int i = 0; i < half_point.size(); ++i) {
    int v = half_point[i];
    ll tmp = p1[v]*(p1[v]-1)%MOD*p2[v]%MOD*(p2[v]-1)%MOD;
    ans = mod(ans-tmp, MOD);
  }
  for (int v = 0; v < N; ++v) {
    for (int i = 0; i < G[v].size(); ++i) {
      int u = G[v][i].to, cost = G[v][i].cost;
      if (u < v) continue;
      if (d1[v]+d2[u]+cost != mi_cost || d1[v]*2 >= mi_cost || d2[u]*2 <= mi_cost) continue;
      ll tmp = p1[v]*(p1[v]-1)%MOD*p2[u]%MOD*(p2[u]-1)%MOD; 
      ans = mod(ans-tmp, MOD);
    }
  }

  cout << ans << endl;
  return 0;
}