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 Lua (LuaJIT 2.1.0) (judge verdict: Accepted)

local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local mod = 1000000007
local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local pow2 = {1}
for i = 2, 28 do pow2[i] = pow2[i - 1] * 2 end
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = pow2[i]
    for j = 0, cnt - 1 do
      self.stage[cnt + j] = self.func(self.stage[(cnt + j) * 2], self.stage[(cnt + j) * 2 + 1])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
  end
  self.stagenum = stagenum
  for i = 1, mul * 2 - 1 do self.stage[i] = emptyvalue end
  for i = 1, n do self.stage[mul + i - 1] = i end
  self:updateAll()
end
SegTree.update = function(self, idx)
  idx = idx + pow2[self.stagenum] - 1
  for i = self.stagenum - 1, 1, -1 do
    local dst = mfl(idx / 2)
    local rem = dst * 4 + 1 - idx
    self.stage[dst] = self.func(self.stage[idx], self.stage[rem])
    idx = dst
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n, m = io.read("*n", "*n")
local s, t = io.read("*n", "*n")
local edge = {}
for i = 1, n do
  edge[i] = {}
end
for i = 1, m do
  local a, b, d = io.read("*n", "*n", "*n")
  edge[a][b], edge[b][a] = d, d
end

local inf = 1000000000 * 99999 + 1
local slen, tlen = {}, {}
local sway = {}
local asked = {}
for i = 1, n do
  slen[i], tlen[i] = inf, inf
  asked[i] = false
  sway[i] = 0
end
slen[s] = 0
sway[s] = 1
asked[n + 1] = true

local function mergefunc(x, y)
  if asked[x] then return y
  elseif asked[y] then return x
  else
    return slen[x] < slen[y] and x or y
  end
end

local st = SegTree.new(n, mergefunc, n + 1)

for i = 1, n do
  local src = st.stage[1]
  if asked[src] then break end
  asked[src] = true
  st:update(src)
  for dst, cost in pairs(edge[src]) do
    if slen[src] + cost < slen[dst] then
      slen[dst] = slen[src] + cost
      sway[dst] = sway[src]
      st:update(dst)
    elseif slen[src] + cost == slen[dst] then
      sway[dst] = badd(sway[dst], sway[src])
    end
  end
end

local stlen = slen[t]
local ret = bmul(sway[t], sway[t])
if inf <= stlen then
  print(0)
  os.exit()
end

local function mergefunc2(x, y)
  if asked[x] then return y
  elseif asked[y] then return x
  else
    return tlen[x] < tlen[y] and x or y
  end
end
st.func = mergefunc2
local tway = {}
for i = 1, n do
  asked[i] = false
  tway[i] = 0
end
tlen[t] = 0
tway[t] = 1
st:updateAll()

for i = 1, n do
  local src = st.stage[1]
  if asked[src] then break end
  asked[src] = true
  if tlen[src] * 2 == stlen then
    local z = bmul(sway[src], tway[src])
    z = bmul(z, z)
    ret = bsub(ret, z)
  end
  st:update(src)
  for dst, cost in pairs(edge[src]) do
    local tlsrc = tlen[src]
    if tlsrc * 2 < stlen and stlen < (tlsrc + cost) * 2
    and tlsrc + cost + slen[dst] == stlen then
      local z = bmul(tway[src], sway[dst])
      z = bmul(z, z)
      ret = bsub(ret, z)
    end
    if tlen[src] + cost < tlen[dst] then
      tlen[dst] = tlen[src] + cost
      tway[dst] = tway[src]
      st:update(dst)
    elseif tlen[src] + cost == tlen[dst] then
      tway[dst] = badd(tway[dst], tway[src])
    end
  end
end
print(ret)