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.
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.
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
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) :