Green Game
Time limit1sMemory limit128 MB
On a bipartite board where Ann and Billy alternately move a pawn, find all starting fields from which Ann can force the first repeated field's cycle to contain a green field.
- Level
Hard8 of 10
- Topics
- Game theory, Graph, DFS, Implementation
- Solved
- No attempts yet
Problem
Green Game is a two-player game played by Ann and Billy. A single pawn is moved across a board of fields, numbered through . Fields through belong to Ann; fields through belong to Billy. Each field is coloured either white or green.
Every field has a non-empty set of successor fields (the fields reachable from it in one move). The successors are arranged so that every move from one of Ann's fields leads to one of Billy's fields, and every move from one of Billy's fields leads to one of Ann's fields.
The pawn starts on a chosen field . The players then move the pawn in turns: from any field, its owner chooses one successor to move to. The first move is made by the owner of the starting field .
The game ends the moment the pawn lands on a field for the second time; call that field . Consider the moves from the first visit of up to its second visit. If the pawn stepped on at least one green field during that stretch, Ann wins; otherwise Billy wins.
Ann has a winning strategy for a starting field if she can play so that she wins no matter how Billy moves.
Given the board, determine every starting field for which Ann has a winning strategy.
Input
The first line contains two positive integers and , separated by a space: the number of fields owned by Ann and by Billy, with .
Each of the next lines describes one field, first Ann's fields (in order ), then Billy's fields (in order ). The -th line describes field and starts with two integers and : the colour ( for white, for green) and the number of successors (). It is followed by the successor field numbers. All integers on a line are separated by single spaces.
At most fields are green, and the total number of successors over all fields is at most .
Output
On the first line, print a single integer : the number of fields for which Ann has a winning strategy. On each of the following lines, print one such field number, in increasing order.