PDP-18 (2006) - Phase C' - 2 (diafonies) **

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 3.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C, C++, Java, Pascal, Python

SCIENTIFIC INTERESTS

At the 10th Panhellenic Conference on Computer Science (HSCSITP 2005), some scientists had different (scientific) opinions from some of their colleagues. For each scientist, we know with whom among the other scientists they disagree. (The "disagreement" relationship is symmetric: If scientist 1 disagrees with scientist 2, then scientist 2 disagrees with scientist 1 as well).

You are asked to develop a program in one of the IOI languages that will check if the scientists can be divided into two working groups so that there are no disagreements within the same group (i.e., no scientists in the same group will disagree with each other). If this is possible, the program should calculate a split into two working groups that do not contain disagreements. Otherwise, it should determine that this is not possible.

INPUT DATA

The file diafonies.in on the first line contains an integer indicating the number of scientists N who participated in the conference, where 10 \le N \le 4\,000. In the next N lines, the following information is given: In ascending order, the numbers of the scientists, the number of other scientists they disagree with, and the numbers of those scientists in ascending order. (All numbers are separated by a space).

OUTPUT DATA

The file diafonies.out contains two (2) lines. In each of the two lines, there is a number indicating the number of scientists in each working group and the increasing numbers of scientists who constitute it. (The first group is the one with the scientist with the smallest increasing number). All numbers are separated by a space. In case the scientists cannot be divided into two groups, the file contains 0 on two lines (empty groups).

Example of Input - Output Files:

STDIN (diafonies.in)

10
1 2 3 9
2 1 4
3 3 1 4 10
4 2 2 3
5 3 7 8 9
6 1 10
7 2 5 10
8 2 5 10
9 2 1 5
10 4 3 6 7 8

STDOUT (diafonies.out)

4 1 4 5 10
6 2 3 6 7 8 9

Maximum execution time: 3 sec.


Comments

There are no comments at the moment.