Under construction

Still being built. Things may change

The Other Way

Time limit2sMemory limit256 MB

Summary
Count the number of distinct shortest paths between two towns in a weighted undirected multigraph, modulo 10^9+9.
Level

Medium5 of 10

Topics
Graph, Shortest path, Dynamic programming
Solved
No attempts yet

Problem

Kir lives in a country with NN towns, numbered 1 through NN. The towns are joined by MM roads, and every road can be walked in both directions.

Kir wants to go from town SS to town EE. He has always taken the same route, so he now wants to walk a different one, and he wonders how many different shortest routes from town SS to town EE there are. Two routes are different when one of them uses a road that the other does not. Roads are counted one by one, so if several roads join the same pair of towns, which road you take changes the route.

A shortest route is one whose total road length is as small as possible.

Answer Kir's question.

Input

The first line contains NN, MM, SS, and EE, separated by single spaces. (2≤N≤1000002 \le N \le 100000, N−1≤M≤300000N-1 \le M \le 300000, 1≤S,E≤N1 \le S, E \le N, S≠ES \neq E)

Each of the next MM lines describes one road with AA, BB, and CC, separated by single spaces. It means a road of length CC joins town AA and town BB in both directions. (1≤A,B≤N1 \le A, B \le N, 1≤C≤10000000001 \le C \le 1000000000)

Several roads may join the same pair of towns, and a road with A=BA = B may appear.

Output

Print the number of shortest routes from town SS to town EE, modulo 1000000009 (109+910^9 + 9). If no route from town SS to town EE exists, print 0.

Examples2

  1. Example 1

    Input
    3 4 1 3
    1 2 1
    2 1 1
    2 3 1
    1 3 2
    
    Expected output
    3
    
  2. Example 2

    Input
    4 3 1 4
    1 2 5
    1 2 7
    3 4 2
    
    Expected output
    0