For each road, decide whether it lies on a shortest path between some pair of offices and list the ones that never do.
Medium4Shortest pathGraphInterviewNo attempts yetTime limit5sMemory limit512 MBThe main campus of company G has N offices, numbered 0 to N−1, and M bidirectional roads, numbered 0 to M−1. Road i joins offices Ui and Vi, and travelling along it takes Ci minutes in either direction.
A path between two different offices X and Y is a sequence of one or more roads that starts at X and ends at Y. The time of a path is the sum of the times of the roads that make it up. At least one path exists between every pair of offices. A shortest path between two offices is a path of minimum total time, and there can be several of them.
Company G sells efficient transport, and the CEO has just realised that her own road network may not be optimal. She wants to know which roads on the campus are inefficient. A road is inefficient when no shortest path between any two different offices contains it.
Given the offices and the roads, find every inefficient road.
The first line contains the number of test cases T. Each test case begins with a line holding two integers N and M, the number of offices and the number of roads. M lines follow, each with three integers Ui, Vi and Ci: road i joins offices Ui and Vi and takes Ci minutes.
Several roads may join the same pair of offices, and a road may have the same office at both ends.
For each test case, print one line with "Case #x:", where x is the test case number starting from 1. Then print the numbers of all inefficient roads in increasing order, one per line. If there is no inefficient road, print only the "Case #x:" line. Road 0 is the first road listed in that test case.