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 Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

// Translate woqja125's code
// 2030742

type Item struct {
	vertex   int
	priority int
	index    int
}

type PriorityQueue []*Item

// For container/heap
func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority > pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(Item)
	item.index = n
	*pq = append(*pq, &item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type edge struct {
	to   int
	cost int
}

const (
	MOD = 1000*1000*1000 + 7
)

var edges [][]edge

func dijkstra(startPos int, distance, count []int) {
	toVisit := make(PriorityQueue, 0, len(distance))

	for i := range distance {
		distance[i] = -1
	}
	count[startPos], distance[startPos] = 1, 0
	toVisit.Push(Item{vertex: startPos, priority: 0})
	heap.Init(&toVisit)
	for toVisit.Len() > 0 {
		point := heap.Pop(&toVisit).(*Item)
		if point.priority != distance[point.vertex] {
			continue
		}
		for _, e := range edges[point.vertex] {
			if distance[e.to] == -1 ||
				distance[e.to] > distance[point.vertex]+point.priority {
				distance[e.to] = distance[point.vertex] + e.cost
				count[e.to] = count[point.vertex]
				heap.Push(&toVisit, Item{vertex: e.to, priority: distance[e.to]})
			} else if distance[e.to] == distance[point.vertex]+point.priority {
				count[e.to] = (count[e.to] + count[point.vertex]) % MOD
			}
		}
	}
	return
}

func main() {
	in := IOInitialize()
	n, m := Int(in), Int(in)
	s, t := Int(in)-1, Int(in)-1
	edges = make([][]edge, n)
	for i := range edges {
		edges[i] = make([]edge, 0, 8)
	}

	for i := 0; i < m; i++ {
		u, v, d := Int(in)-1, Int(in)-1, Int(in)

		edges[u] = append(edges[u], edge{to: v, cost: d})
		edges[v] = append(edges[v], edge{to: u, cost: d})
	}
	distanceFromS := make([]int, n)
	distanceFromT := make([]int, n)
	CountFromS := make([]int, n)
	CountFromT := make([]int, n)

	dijkstra(s, distanceFromS, CountFromS)
	dijkstra(t, distanceFromT, CountFromT)

	c := make([]int, 0, (n/10)+10)
	OptLength, ans, S := distanceFromS[t], 0, 0
	for i := range distanceFromS {
		if distanceFromS[i] == distanceFromT[i] {
			c = append(c, CountFromS[i]*CountFromT[i]%MOD)
		}
		if distanceFromS[i]*2 >= OptLength {
			continue
		}
		for _, e := range edges[i] {
			if distanceFromS[i]+e.cost+distanceFromT[e.to] != OptLength {
				continue
			}
			if distanceFromT[e.to]*2 < OptLength {
				c = append(c, CountFromS[i]*CountFromT[e.to]%MOD)
			}
		}
	}
	for _, x := range c {
		S = (S + x) % MOD
	}
	for _, x := range c {
		ans = (ans + x*(S-x+MOD)) % MOD
	}

	fmt.Println(ans)
}

//////////
func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}