Reliable Nets
Time limit1sMemory limit128 MB
For each graph, find the minimum cost of a spanning subgraph that stays connected after removing any single edge, or report that none exists.
- Level
Hard8 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Brute force
- Solved
- No attempts yet
Problem
You are in charge of designing a campus network connecting several buildings, and you care about both its reliability and its cost. To add redundancy while keeping the price as low as possible, you want to build the cheapest network such that, if any single line breaks, all buildings can still communicate with one another. Such a network is called a minimal reliable net.
Input
There are multiple test cases. Each test case begins with a line containing two integers () and (): the number of buildings (numbered through ) and the number of potential inter-building connections. (A line with marks the end of input.) Each of the next lines contains three positive integers b1 b2 c, meaning it costs to connect buildings b1 and b2. All connections are bidirectional.
Output
For each test case, print one line. If a minimal reliable net exists, print
The minimal cost for test case p is c.
where is the test case number (starting at ) and is the minimal total cost. If no reliable net is possible, print
There is no reliable net possible for test case p.