Close
Topic list
Possible Bipartition
MEDIUM
20 mins
Graph
Topics (Covered in this problem)
Problem solved
Skill meter
Graph
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Possible Bipartition

Contributed by
Yash_5830
Medium
0/80
Avg time to solve 20 mins
Success Rate 80 %
Share

## Problem Statement

#### 3. Each person from the set belongs to exactly one group.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
5 4
1 2
1 3
1 4
1 5
5 5
2 3
3 4
4 5
1 5
1 2
``````
##### Sample Output 1:
``````1
0
``````
##### Explanation for Sample Input 1:
``````In the first test case, there is a set of 5 people and the size of the dislike matrix is 4. Pairs of people who dislike each other are {1,2}, {1,3}, {1,4}, {1,5}.
It means we can divide the given set of 5 people into two groups by keeping Person 1 in the first group and all the other people in the second group.

In the second test case, there is a set of 5 people and the size of the dislike matrix is 5. Pairs of people who dislike each other are {2,3}, {3,4}, {4,5}, {1,5}, {1,2}.
There is no possible division that can divide the set of 5 people into 2 groups.
``````
##### Sample Input 2:
``````2
4 3
1 2
1 3
2 4
10 9
1 2
1 3
1 4
1 5
1 8
1 6
1 9
1 7
1 10
``````
##### Sample Output 2:
``````1
1
``````
Auto
Console