#P1608. Counting Shortest Paths in a Directed Graph

    ID: 14894 Type: Default 1000ms 256MiB

Counting Shortest Paths in a Directed Graph

Counting Shortest Paths in a Directed Graph

In this problem, you are given a directed graph representing towns and roads. The graph consists of NN nodes (towns) and MM directed edges. Town 11 is the starting point and town NN is the destination. Each edge from town II to town JJ requires D[I,J]D[I,J] time. Your task is to find the number of distinct shortest paths from town 11 to town NN. Two paths are considered different if the sequence of towns is different. If there is no path from town 11 to town NN, output 00.

inputFormat

The first line contains two integers NN and MM, representing the number of towns and the number of directed roads, respectively. Each of the following MM lines contains three integers II, JJ, and DD, representing a one-way road from town II to town JJ with a travel time of DD.

outputFormat

Output a single integer representing the number of distinct shortest paths from town 11 to town NN.

sample

4 5
1 2 1
1 3 1
2 4 1
3 4 1
2 3 1
2