ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

Tetrahedron Team Programming Contest May 2001

About     Problems     Submit solution     Judge status     Standings
Contest is over

G. Two Teams

Time limit: 1.0 second
Memory limit: 64 MB
The group of people consists of N members. Every member has one or more friends in the group. You are to write program that divides this group into two teams. Every member of each team must have friends in another team.


The first line of input contains the only number N (N ≤ 100). Members are numbered from 1 to N. The second, the third,…and the (N+1)th line contain list of friends of the first, the second, …and the Nth member respectively. This list is finished by zero. Remember that friendship is always mutual in this group.


The first line of output should contain the number of people in the first team or zero if it is impossible to divide people into two teams. If the solution exists you should write the list of the first group into the second line of output. Numbers should be divided by single space. If there are more than one solution you may find any of them.


2 3 0
3 1 0
1 2 4 5 0
3 0
3 0
7 0
6 0
2 4 5 6
Problem Author: Dmitry Filimonenkov
Problem Source: Tetrahedron Team Contest May 2001
To submit the solution for this problem go to the Problem set: 1106. Two Teams