The Other Way
Time limit2sMemory limit256 MB
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 towns, numbered 1 through . The towns are joined by roads, and every road can be walked in both directions.
Kir wants to go from town to town . 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 to town 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 , , , and , separated by single spaces. (, , , )
Each of the next lines describes one road with , , and , separated by single spaces. It means a road of length joins town and town in both directions. (, )
Several roads may join the same pair of towns, and a road with may appear.
Output
Print the number of shortest routes from town to town , modulo 1000000009 (). If no route from town to town exists, print 0.