Two Teams (Check Whether Graph is Bipartite or Not)
Determine if a given undirected graph can be divided into exactly two disjoint cliques. Print 1 if possible, otherwise print 0.
Input:
The first line contains an integer 'T' indicating the number of test cases.
For each test case, the first line has two space-separated integers 'N' and 'M' where 'N' represents the total nodes, and 'M' represents the total edges.
Each of the next 'M' lines contains two space-separated integers 'U' and 'V', representing an edge between nodes U and V.
Output:
Output 1 if the graph can be divided into two disjoint cliques, otherwise output 0 for each test case on a new line.
Example:
Example is not directly provided.
Constraints:
1 ≤ T ≤ 5
1 ≤ N ≤ 100
1 ≤ M ≤ N * (N - 1) / 2
0 ≤ U, V ≤ N - 1
Note:
No need to print anything; you just need to implement the function to return the result.
A subgraph G is a clique if it is a complete graph, and cliques are disjoint if they have no common nodes.
AnswerBot
5d
Check if a given undirected graph can be divided into exactly two disjoint cliques.
Create an adjacency list to represent the graph
Use BFS or DFS to check if the graph is bipartite
If the graph is bipar...read more
Help your peers!
Add answer anonymously...
Top Cadence Design Systems SDE-2 interview questions & answers
Popular interview questions of SDE-2
>
Cadence Design Systems SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app