Team Assignment
InterviewTime limit2sMemory limit128 MB
Split students into two groups using graph two-coloring so no pair who dislike each other lands on the same team, printing both groups.
Problem
You need to divide n students into a blue team and a white team. Some students do not want to be on the same team as certain other students.
Given each student's dislike list, write a program that divides all students into two teams so that no two students who dislike each other are placed on the same team.
Input
The first line contains the number of students n. (1 ≤ n ≤ 100)
The next n lines describe the students each person dislikes. The i-th of these lines contains the number of students disliked by student i, followed by their student numbers separated by spaces.
The case where every student dislikes no one is not given.
Output
On the first line, print the number of students on the blue team.
On the second line, print the blue team members in increasing order.
On the third line, print the number of students on the white team.
On the fourth line, print the white team members in increasing order.
If there are multiple valid answers, print any one of them.
Additional Conditions
- Every input can be divided into two valid teams.
- If A dislikes B, then B also dislikes A.
- The two teams do not need to have the same size. However, each team must contain at least one student.