You are given an undirected graph of ‘N’ nodes and ‘M’ edges. Your task is to print 1 if this graph can be divided into exactly two disjoint cliques. Else, you need to print 0.
Note :Let G be a subgraph of the given graph. Then, G is said to be a clique if G is a complete graph.
Two cliques are said to be disjoint if they don’t have a common node.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains two space-separated integers ‘N’ and ‘M’. Here ‘N’ denotes the total number of nodes and ‘M’ denotes the total number of edges in the graph.
The next ‘M’ lines contain two space-separated integers ‘U’ and ‘V’. Here ‘U’ and ‘V’ represent the nodes that share an edge.
Output Format :
For each test case, print 1 if the given graph can be divided into exactly two disjoint cliques, else print 0.
The output of each test case will be printed in a separate line.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 100
1 <= M <= N * (N - 1) / 2
0 <= U, V <= N - 1
2
4 2
0 1
2 3
5 4
0 1
0 2
0 3
2 4
1
0
Test Case 1 :
The given graph is shown below.
The above graph can be divided into two disjoint cliques {0, 1} and {2, 3}.
Test Case 2 :
The given graph is shown below.

The above graph cannot be divided into two disjoint cliques.
2
6 7
0 1
0 2
1 2
3 2
3 4
3 5
4 5
5 4
0 1
0 4
1 2
2 3
1
0
Take complement of the graph and try to find a solution using properties of the bipartite graph.
The idea here is first to take a complement of the graph. Then the problem reduces to check if the given graph is a bipartite graph or not. Because bipartite is a graph that can be divided into two sets such that no two nodes of the same set have a common edge it means in the original graph every two nodes of the same set are completely connected i.e. the set will be a complete graph.
To check whether a graph is bipartite or not we will color the graph using 2 colors such that adjacent elements will have different colors. If we are not able to do such coloring then it shows that the bipartite graph is not possible.
Algorithm:
Description of isBipartite function :
This function is used to check whether the subgraph starting from vertex ‘u’ is a bipartite graph or not.
This function will take 3 arguments
bool isBipartite(u, color, adj) :
O(N ^ 2), where ‘N’ is the total number of nodes in the graph.
Building an adjacency matrix of graph takes O(N ^ 2) time. Also, checking whether the graph is a bipartite or not takes O(N) time as we need to visit O(N) nodes in the worst case.
Hence, the overall time complexity will be O(N ^ 2) + O(N) = O(N ^ 2).
O(N ^ 2), where ‘N’ is the total number of nodes in the graph.
We are using a distance color that takes O(N) space. Also, we are using a queue that takes O(N) space as there can be O(N) nodes in the queue in the worst case. Also, we are using an Adjacency matrix that takes O(N ^ 2) space.
Hence, the overall space complexity will be O(N) + O(N) + O(N ^ 2) = O(N ^ 2).