RELINETS - Reliable Nets


You’re in charge of designing a campus network between buildings and are very worried about its reliability and its cost. So, you’ve decided to build some redundancy into your network while keeping it as inexpensive as possible. Specifically, you want to build the cheapest network so that if any one line is broken, all buildings can still communicate. We’ll call this a minimal reliable net.

Input

There will be multiple test cases for this problem. Each test case will start with a pair of integers n (<=15) and m (<= 20) on a line indicating the number of buildings (numbered 1 through n) and the number of potential inter-building connections, respectively. (Values of n = m = 0 indicate the end of the problem.) The following m lines are of the form b1 b2 c (all positive integers) indicating that it costs c to connect building b1 and b2. All connections are bidirectional.

Output

For each test case you should print one line giving the cost of a minimal reliable net. If there is a minimal reliable net, the output line should be of the form:

The minimal cost for test case p is c.

where p is the number of the test case (starting at 1) and c is the cost. If there is no reliable net possible, output a line of the form:

There is no reliable net possible for test case p.

Example

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

Output:
The minimal cost for test case 1 is 6.
There is no reliable net possible for test case 2.

hide comments
vineetjai: 2020-11-08 09:45:57

O(2^m*m*m) complexity passed.

nadstratosfer: 2019-12-01 05:45:08

Cool problem. Enjoyed everything between coding 2 wrong solutions and a testcase generator, lengthy analysis of what can be going wrong and finally an unexpected AC in PyPy with not really the most elegant code I've ever produced.

Antonio Roberto Paoli: 2018-09-26 18:35:27

A semi-Eulerian graph (a graph with exact 2 nodes with grade 3) is reliable too. I think the solution asked does not consider this hipotesis. So this test case would be reliable.
5 6
1 2 1
1 3 1
1 4 1
2 5 1
3 5 1
4 5 1
0 0

Last edit: 2018-09-26 20:29:02
shubham_9008: 2018-05-16 17:38:42

pls sb give a suggestion on how to solve this problem



shiv2111: 2018-01-18 08:31:09

easy peasy :|

sxie12: 2017-06-29 23:49:31

Don't compare with spojtoolkit. It has an incorrect solution.

krist7599555: 2016-12-21 14:47:53

test case is weak in some case
5 6
1 2 1
1 3 1
1 4 1
2 5 1
3 5 1
4 5 1
0 0
I think this case is minimal reliable,
but i say it is "no reliable" I still get accept !?
my wrong solution ( just little greedy with degree of neighbor node, for all degree is Even that >= 2 ) this solution still get accept (WHY?),
Hope you fix this bug :)

Last edit: 2016-12-21 14:48:36
Kushal Saharan: 2015-10-21 15:35:39

Getting TLE, tried to find connected graphs without bridges for every possible edge set and picked up the minimum cost set. Any suggestions how to improve this?

Hussain Kara Fallah: 2014-02-08 09:35:28

why is the limits so loose :\


Added by:Camilo Andrés Varela León
Date:2007-07-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:East Central North America 2005