Description
Bowo is fed up with his body shape. He has a tall posture, but he’s very skinny. No matter how much
he eats, he never gains any weight. Even though he is a computer geek (and he loves it), he wants
a pretty and non-geek girlfriend. Unfortunately, most girls in his surrounding do not like skinny and
unattractive guy. Therefore, Bowo has decided to gain some muscles in his body; he joined a fitness
club and begun to do some body building exercises.
There are a lot of exercise equipments in a fitness club, and usually there should be weightlifting
equipments such as barbell and dumbbell (barbell with shorter rod). Upon seeing a dumbbell, Bowo
cannot help but imagining graphs which are similar to a dumbbell. A graph — which later referred as
“connected component” — of N nodes is called a dumbbell if it fulfills all the following conditions:
(i) All nodes in the graph can be partitioned into two disjoint sets P and Q which have equal size,
i.e. N/2 nodes each.
(ii) Both induced subgraph of P and Q are complete graphs.
(iii) P and Q are connected by exactly one edge.
Informally, a dumbbell is obtained by connecting two equal size complete graphs with an edge.
For example, consider graph A in Figure 1 with 10 nodes and 21 edges. There are two disjoint
complete graphs of size 5 which are connected by an edge. Therefore, this graph is a dumbbell. Graph
B and C are also dumbbells. Graph D, on the other hand, is not.
Figure 1.
Given a graph (which might be disconnected), determine how many connected components which
are dumbbells. A connected component is a connected subgraph which no vertex can be added and
still be connected.
Input
The first line of input contains an integer T (T ≤ 50) denoting the number of cases. Each case begins
with two integers: N and M (1 ≤ N ≤ 100; 0 ≤ M ≤ 4, 950) denoting the number of nodes and edges
in the graph respectively. The nodes are numbered from 1 to N. The following M lines each contains
two integer: a and b (1 ≤ a, b ≤ N; a ̸= b) representing an undirected edge connecting node a and node
b. You are guaranteed that each pair of nodes has at most one edge in the graph.
Output
For each case, output ‘Case #X: Y ’, where X is the case number starts from 1 and Y is the number
of connected components which are dumbbells for the respective case.
Explanation for 1st sample case:
There is only one node in the graph; a dumbbell requires at least two nodes.
Explanation for 2nd sample case:
Both connected components are dumbbells: {1, 2} and {3, 4}.
Explanation for 3rd sample case:
There are two connected components: {1, 2, 3, 4, 5, 6}, and {7, 8, 9, 10}, and both of them are
dumbbells. The first one is dumbbell with complete graph of size 3, while the second one has size of 2.
Explanation for 4th sample case:
There are four connected components: {1, 2}, {3, 4}, {5, 6} and {7, 8, 9}. Only the first three are
dumbbells.