Reliable Nets

Time limit1sMemory limit128 MB

Summary
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 nn (n≤15n \le 15) and mm (m≤20m \le 20): the number of buildings (numbered 11 through nn) and the number of potential inter-building connections. (A line with n=m=0n = m = 0 marks the end of input.) Each of the next mm lines contains three positive integers b1 b2 c, meaning it costs cc 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 pp is the test case number (starting at 11) and cc is the minimal total cost. If no reliable net is possible, print

There is no reliable net possible for test case p.

Examples1

  1. Example 1

    Input
    4 5
    1 2 1
    1 3 2
    2 4 2
    3 4 1
    2 3 1
    2 1
    1 2 5
    0 0
    
    Expected output
    The minimal cost for test case 1 is 6.
    There is no reliable net possible for test case 2.