Under construction

Still being built. Things may change

Team Assignment

Interview

Time limit2sMemory limit128 MB

Summary
Split students into two groups using graph two-coloring so no pair who dislike each other lands on the same team, printing both groups.
Level

Medium4 of 10

Topics
Graph, BFS, DFS
Solved
No attempts yet

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

  1. Every input can be divided into two valid teams.
  2. If A dislikes B, then B also dislikes A.
  3. The two teams do not need to have the same size. However, each team must contain at least one student.

Examples1

  1. Example 1

    Input
    5
    1 3
    1 5
    2 1 4
    1 3
    1 2
    
    Expected output
    3
    1 4 5
    2
    2 3