#P8371. [POI 2001 R1] 绿色游戏

[POI 2001 R1] 绿色游戏

Problem Description

Green Game is a two-player game. The two players are called Ann\text{Ann} and Billy\text{Billy}. The game consists of moving a single token on a board in turns.

Some points on the board are green, and the rest are white. All points are numbered from 11 to a+ba+b. Points numbered 11 to aa belong to Ann\text{Ann}, and points numbered a+1a+1 to a+ba+b belong to Billy\text{Billy}. Each point has some successor points that can be reached in one move. The successors of a point belonging to Ann\text{Ann} must belong to Billy\text{Billy}, and vice versa. Every point has at least one successor point, so it is always possible to move one step forward.

At the start of the game, the token is placed on an arbitrary point PP. Then the players alternately move the token from the current point (which belongs to the player whose turn it is) to one of its successor points (which belongs to the opponent). The owner of point PP moves first. The game ends when the token reaches some point for the second time; call this point QQ. If, during the sequence of moves from point QQ back to point QQ, the token is placed on a green point at least once, then Ann\text{Ann} wins. If, starting from point PP, no matter how Billy\text{Billy} moves, Ann\text{Ann} can always guarantee winning the game, then we say that Ann\text{Ann} has a winning strategy for the starting point PP.

Write a program to:

  1. Read the description of the board.

  2. Determine all starting points for which Ann\text{Ann} has a winning strategy.

Input Format

The first line contains two integers aa and bb, separated by a single space, representing the numbers of points belonging to Ann\text{Ann} and Billy\text{Billy}, respectively (1a,b3000)(1 \le a, b \le 3000). The next a+ba+b lines describe the points, first all of Ann\text{Ann}'s points, then all of Billy\text{Billy}'s points.

Line i+1i+1 (1ia+b)(1 \le i \le a+b) starts with integers z,kz, k: zz denotes the color of point ii (00 for white, 11 for green), and kk denotes the number of successor points. Then follow kk integers on the same line, giving the indices of the successor points, separated by single spaces. The number of green points does not exceed 100100, and the sum of the numbers of successor points over all points does not exceed 3000030000.

Output Format

The first line contains a single integer LL, the number of starting points for which Ann\text{Ann} has a winning strategy. The next LL lines list these point indices in increasing order, one per line.

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

Hint

Translated by ChatGPT 5