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
4mo

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!
Select
Add answer anonymously...

Cadence Design Systems SDE-2 interview questions & answers

A SDE-2 was asked 3mo agoQ. Design a data structure that supports the following two operations: void addNum(...read more
A SDE-2 was asked 3mo agoQ. How would you sort an array based on a user-defined order?
A SDE-2 was asked 3mo agoQ. What is a copy constructor?

Popular interview questions of SDE-2

A SDE-2 was asked 2mo agoQ1. Design a data structure that supports the following two operations: void addNum(...read more
A SDE-2 was asked 2mo agoQ2. How would you sort an array based on a user-defined order?
A SDE-2 was asked 2mo agoQ3. What is a copy constructor?
Cadence Design Systems SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits