#P6413. [COCI 2008/2009 #3] NAJKRACI
[COCI 2008/2009 #3] NAJKRACI
Description
There is a directed graph with vertices and edges.
For each edge, compute (modulo ) how many times it is used by shortest paths between any pair of vertices.
If there are multiple shortest paths between vertices and , then each shortest path is counted once. You can refer to the output of the 3rd and 4th edges in Sample 4 to understand this sentence.
Input Format
The first line contains two integers and .
The next lines each contain three integers , , , meaning there is a directed edge from to with weight .
Output Format
Output lines.
Each line outputs one integer. The value on the -th line represents (modulo ) the number of times the edge read on line is used by shortest paths between any pair of vertices.
4 3
1 2 5
2 3 5
3 4 5
3
4
3
4 4
1 2 5
2 3 5
3 4 5
1 4 8
2
3
2
1
5 8
1 2 20
1 3 2
2 3 2
4 2 3
4 2 3
3 4 5
4 3 5
5 4 20
0
4
6
6
6
7
2
6
4 4
1 2 1
2 3 1
1 3 2
3 4 1
3
4
2
4
Hint
Constraints and Notes
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , , , , .
Explanation
This problem is translated from Croatian Open Competition in Informatics 2008/2009, Contest #3, T6 NAJKRACI.
Translated by ChatGPT 5
京公网安备 11011102002149号