Rings’n’Ropes

I have n tiny rings made of steel. I also have m pieces of rope, all of exactly the same length. The two ends of each piece of rope are tied to two different rings. I am going to take one of the rings, L, into my left hand, and another ring, R into my right hand. Then I will pull the whole structure apart as hard as I can. Some of the ropes will be streched horizontally because of this. Others will hang down or bend out of shape. If I want the number of horizontally stretched ropes to be as large as possible, which L and R should I pick? Assume that the stretching of ropes in negligible, they all have negligible thickness and are free to slide around the rings that they are tied to. The thickness and radius of each ring is negligible, too. Input The first line of input gives the number of cases, N. N test cases follow. Each one starts with two lines containing n (2 ≤ n ≤ 120) and m (0 ≤ m ≤ n(n−1)/2). The next m lines will each contain a pair of different rings (integers in the range [0, n − 1]). Each pair of rings will be connected by at most one rope. Output For each test case, output the line containing ‘Case #x:’, followed by the largest number of ropes that I can stretch horizontally by picking a pair of rings, L and R. Sample Input 4 2 1 01 3 3 01 12 20 6 6 01 05 13 54 32 42 6 7 “Well, that seems to be the situation. But, I don’t want that, and you don’t want that, and Ringo here definitely doesn’t want that.” Jules Winnfield

2/2 01 05 13 14 54 32 42 Sample Output Case #1: 1 Case #2: 1 Case #3: 6 Case #4: 7