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: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x;

    int y,z;
    //string r;
    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
struct S
{
    int x,y;
};
vector<P> v[100333];
//bitset<4001000> bit;
int a,c,i,b,k,d,n,m,e=1987654321;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[200200];
int o[152202];
int j[5][200100];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z[5][100100],mod=1000000007;
P u[2222];
//int j[31][11111];

stack<S> s;
queue<int> q;


//deque<int> de;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<string,int > p;
//list<int> l;
string r,r1,r2;
//char r[33][33];

bool as(int a,int b)
{
    return a>b;
}

long long f(int i,int n)
{
    if(l[i]==n) return 1;
    if(z[i][n]) return z[i][n];
    long long x=0;
    for(int h=0;h<v[n].size();h++)
    {
        //printf("@%d %d %d %d %d\n",n,v[n][h].x,j[i][n],j[i][v[n][h].x],v[n][h].y);
        if(j[i][n]==j[i][v[n][h].x]+v[n][h].y)
        {

            x+=f(i,v[n][h].x),x%=mod;
        }
    }
    return z[i][n]=x;
}

int main()
{
    //memset(z,-1,sizeof(z));
    scanf("%d %d %d %d",&a,&b,&l[1],&l[2]);
    for(int t=1;t<=b;t++)
    {
        n=t;
        m=t+1;
        i=1;
        //scanf("%d %d %d",&n,&m,&i);
        v[n].push_back({m,i});
        v[m].push_back({n,i});
    }
    memset(j,-1,sizeof(j));
    for(int u=1;u<=2;u++)
    {
        j[u][l[u]]=0;
        q.push(l[u]);
        for(;q.size();q.pop())
        for(int h=0;h<v[q.front()].size();h++)
        if(j[u][v[q.front()][h].x]<0||j[u][v[q.front()][h].x]>j[u][q.front()]+v[q.front()][h].y)
        {
            j[u][v[q.front()][h].x]=j[u][q.front()]+v[q.front()][h].y;
            q.push(v[q.front()][h].x);
        }
    }
   /* y=f(1,l[2]);
    x=y*y%mod;
    for(int t=1;t<=a;t++)
        if(j[1][t]==j[2][t]&&j[2][t]*2==j[1][l[2]])
        //if(t!=l[1]&&t!=l[2])
        x-=f(1,t)*f(1,t)%mod*f(2,t)%mod*f(2,t)%mod,x+=mod,x%=mod;
    for(int t=1;t<=a;t++)
        for(int h=0;h<v[t].size();h++)
        //if(t>v[t][h].x)
        if(v[t][h].y+j[1][t]+j[2][v[t][h].x]==j[1][l[2]]&&max(j[1][t],j[2][v[t][h].x])<min(j[1][t],j[2][v[t][h].x])+v[t][h].y)
            x-=f(1,t)*f(1,t)%mod*f(2,v[t][h].x)%mod*f(2,v[t][h].x)%mod,x+=mod,x%=mod;
    *///for(int t=1;t<=a;t++)
    printf("%lld ",x);
}