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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    int N, M;
    List<Tuple<int, int>>[] es;
    int S, T;
    int[] L;
    int[] R;
    int[] D;

    void calc()
    {
        cin = new Scanner();
        N = cin.nextInt();
        M = cin.nextInt();

        S = cin.nextInt() - 1;
        T = cin.nextInt() - 1;

        es = new List<Tuple<int, int>>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<Tuple<int, int>>();
        }
        L = new int[M];
        R = new int[M];
        D = new int[M];
        for (int i = 0; i < M; i++)
        {
            int l, r, d;
            l = cin.nextInt() - 1;
            r = cin.nextInt() - 1;
            d = cin.nextInt();
            L[i] = l;
            R[i] = r;
            D[i] = d;
            es[l].Add(Tuple.Create(r, d));
            es[r].Add(Tuple.Create(l, d));
        }

        long[] dpS = new long[N];
        long[] dpT = new long[N];
        long[] distS = dijkstra(S, dpS);
        long[] distT = dijkstra(T, dpT);
        bool[] ok = new bool[N];
        for (int i = 0; i < N; i++)
        {
            if (distS[i] + distT[i] == distS[T])
            {
                ok[i] = true;
            }
        }

        long ans = dpS[T] * dpT[S] % mod;
        for (int i = 0; i < N; i++)
        {
            if(ok[i] && distS[i] == distT[i])
            {
                long tmp = dpS[i] * dpT[i] % mod;
                tmp = tmp * tmp % mod;
                ans -= tmp;
                if (ans < 0) ans += mod;
            }
        }

        for (int i = 0; i < M; i++)
        {
            if (ok[L[i]] && ok[R[i]])
            {
                if (distS[L[i]] == distT[L[i]]) continue;
                if (distS[R[i]] == distT[R[i]]) continue;
                if ((distS[L[i]] < distT[L[i]]) != (distS[R[i]] < distT[R[i]]))
                {
                    int a = L[i];
                    int b = R[i];
                    if (distS[a] > distS[b]) swap(ref a, ref b);
                    long tmp = dpS[a] * dpT[b] % mod;
                    tmp = tmp * tmp % mod;
                    ans -= tmp;
                    if (ans < 0) ans += mod;
                }
            }
        }
        Console.WriteLine(ans);
    }

    //swap
    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    } 

    long mod = 1000000007;


    long[] dijkstra(int start, long[] DP)
    {
        long[] dist = new long[N];
        long MAX = long.MaxValue / 2;
        for (int i = 0; i < N; i++)
        {
            dist[i] = MAX;
        }
        dist[start] = 0;
        DP[start] = 1;
        Heap<Tuple<long, int>> h = new Heap<Tuple<long, int>>(); //cost, pos
        h.push(Tuple.Create(0L, start));

        while (h.top != null)
        {
            var now = h.pop();
            int nowp = now.Item2;
            long nowcost = now.Item1;
            if (nowcost > dist[nowp]) continue;
            

            foreach (var next in es[nowp])
            {
                int nextp = next.Item1;
                long nextcost = nowcost + next.Item2;
                if(dist[nextp] > nextcost)
                {
                    dist[nextp] = nextcost;
                    DP[nextp] = DP[nowp];

                    h.push(Tuple.Create(nextcost, nextp));
                }
                else if(dist[nextp] == nextcost)
                {
                    DP[nextp] += DP[nowp];
                    if (DP[nextp] >= mod) DP[nextp] -= mod;
                }
            }
        }
        return dist;
    }


    class Heap<T> where T : IComparable
    {
        public HeapNode<T> top;

        public Heap() { }

        public void push(T val)
        {
            top = HeapNode<T>.meld(top, new HeapNode<T>(val));
        }

        public T pop()
        {
            T ret = top.val;
            top = HeapNode<T>.meld(top.r, top.l);
            return ret;
        }

        public void merge(Heap<T> h2)
        {
            top = HeapNode<T>.meld(top, h2.top);
        }

        public class HeapNode<NT> where NT : IComparable
        {
            public HeapNode<NT> l, r;
            public NT val;

            public HeapNode(NT _val)
            {
                val = _val;
            }

            public static HeapNode<NT> meld(HeapNode<NT> a, HeapNode<NT> b)
            {
                if (a == null) return b;
                if (b == null) return a;
                if (a.val.CompareTo(b.val) > 0)
                {
                    HeapNode<NT> temp = a;
                    a = b;
                    b = temp;
                }
                a.r = meld(a.r, b);
                HeapNode<NT> temph = a.l;
                a.l = a.r;
                a.r = temph;
                return a;
            }
        }
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}