In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you are familiar with IRC chat, the support team is also reachable on PIRC network (irc.pirc.pl
) in #szkopul
channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
"Green game" is a game for two players, say Ann and Billy. Their task is to shift a pawn on the board. Some fields of the board are green, the rest is white. All of them are numbered by integers from the interval . The fields with integers from the interval
belong to Ann, the fields with numbers
to Billy.
For each field there is given a set of successors, containing the fields one can get to from this field in one move. These sets were chosen in such a way that from the field belonging to Ann one can get in one move to the Billy's fields only, and vice versa. All the fields have non-empty sets of successors, thus one can always make a move.
At the beginning of the game we put a pawn on the arbitrarily chosen start field , then players shift the pawn by turns from their field to any successor of this field (we know it belongs to the opponent). The game is started by an owner of the start field
. The game is finished when the pawn stays for the second time on the same field, say the field
. If in the sequence of moves from the field
to the field
taken for the second time, the pawn was put at least once on the green field, Ann wins the game, otherwise Billy wins. We say that Ann has a winning strategy for the given start field
in case when there is such a method, which guarantees that she wins the game beginning from this field, no matter what moves Billy makes.
Write a program which:
In the first line of the standard input there are written two positive integers ,
, separated by a single space, meaning respectively: the number of fields belonging to Ann, the number of fields belonging to Billy. Integers
,
satisfy the condition:
. In the following a+b lines there are descriptions of the fields of the board: first, descriptions of fields belonging to Ann, and then, of ones belonging to Billy. The
-st line, for
, begins with integers
,
meaning respectively the colour of the field
(0 means white, 1 - green) and the number of successors of this field. Then
integers (
) are written (still in the same line). They are the numbers denoting the successors of the
-th field. The integers in each line are separated by single spaces. The number of green fields on the board is not greater than
. The total number of successors of all the fields on the board is not grater than
.
The first line of the standard output should contain exactly one integer , which indicates the number of fields for which Ann has a winning strategy. The following
lines should contain numbers of these fields written in ascending order - each integer should be written in a separate line.
For the input data:
5 3 0 2 6 7 0 3 6 7 8 0 1 8 1 1 7 1 1 8 1 2 1 2 0 2 1 2 0 2 3 4
the correct result is:
5 1 2 4 6 7
Task author: Marcin Jurdzinski.