1341. Green game

单点时限: 2.0 sec

内存限制: 256 MB

“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 1…(a+b). The fields with integers from the interval 1…a belong to Ann, the fields with numbers (a+1)…(a+b) 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 P, 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 P. The game is finished when the pawn stays for the second time on the same field, say the field Q. If in the sequence of moves from the field Q to the field Q 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 P 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.

Task

Write a program which:

1.reads the description of the board,

2.computes the set of fields for which Ann has a winning strategy,

3.writes the result.

输入格式

In the first line there are written two positive integers a, b, separated by a single space, meaning respectively: the number of fields belonging to Ann, the number of fields belonging to Billy. Integers a, b satisfy the condition: 1 <= a+b <= 3000. 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 (i+1)-st line, for 1 <= i <= a+b, begins with integers z, k meaning respectively the colour of the field i (0 means white, 1 - green) and the number of successors of this field. Then k integers (1 <= k < a+b) are written (still in the same line). They are the numbers denoting the successors of the i-th field. The integers in each line are separated by single spaces. The number of green fields on the board is not greater than 100. The total number of successors of all the fields on the board is not grater than 30000.

输出格式

The first line should contain exactly one integer l, which indicates the number of fields for which Ann has a winning strategy. The following l lines should contain numbers of these fields written in ascending order - each integer should be written in a separate line.

样例

Input
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
Output
5
1
2
4
6
7

0 人解决,2 人已尝试。

0 份提交通过,共有 4 份提交。

9.9 EMB 奖励。

创建: 16 年,9 月前.

修改: 6 年,8 月前.

最后提交: 1 年,4 月前.

来源: POI 2001 I Stage

题目标签