gCampus (Small)
InterviewTime limit5sMemory limit512 MB
For each road, decide whether it lies on a shortest path between some pair of offices and list the ones that never do.
- Level
Medium4 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
The main campus of company G has offices, numbered 0 to , and bidirectional roads, numbered 0 to . Road joins offices and , and travelling along it takes minutes in either direction.
A path between two different offices and is a sequence of one or more roads that starts at and ends at . 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.
Input
The first line contains the number of test cases . Each test case begins with a line holding two integers and , the number of offices and the number of roads. lines follow, each with three integers , and : road joins offices and and takes minutes.
Several roads may join the same pair of offices, and a road may have the same office at both ends.
Limits
Output
For each test case, print one line with "Case #x:", where 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.