#P8371. Green Game Strategy
Green Game Strategy
Green Game Strategy
Two players, (\text{Ann}) and (\text{Billy}), play a game on a directed board of (a+b) nodes. The nodes are numbered from (1) to (a+b); nodes (1) to (a) belong to (\text{Ann}) and nodes (a+1) to (a+b) belong to (\text{Billy}). Each node is colored either green or white. It is guaranteed that every node has at least one successor and that the successors of an (\text{Ann}) node lie in ({a+1,a+2,\dots,a+b}) while the successors of a (\text{Billy}) node lie in ({1,2,\dots,a}\n\nThe game starts by placing a pawn on an arbitrary starting node (P). The owner of (P) makes the first move by moving the pawn to one of the successors of (P) (which belong to the opponent). Players alternate moves. The game ends when some node (Q) is visited for the second time. Let the cycle be the sequence of moves starting at the first appearance of (Q) and ending when (Q) is repeated. (\text{Ann}) wins if at least one green node appears in this cycle; otherwise, (\text{Billy}) wins.
A starting node (P) is said to be a winning position for (\text{Ann}) if, regardless of how (\text{Billy}) moves, (\text{Ann}) can force a win. In this problem, you must determine all starting nodes for which (\text{Ann}) has a winning strategy.
Note: All formulas are given in (\LaTeX) format.
inputFormat
Input Format:
The first line contains two integers (a) and (b), where (a) is the number of nodes owned by (\text{Ann}) and (b) is the number of nodes owned by (\text{Billy}).
Then follow (a+b) lines, one for each node from (1) to (a+b). Each line contains a character (C) (either 'G' for green or 'W' for white), an integer (k) (the number of successors), followed by (k) integers indicating the successors of this node.
It is guaranteed that for a node (i) owned by (\text{Ann}) (i.e. (1 \le i \le a)), all successors lie in ({a+1,\dots,a+b}) and for a node (i) owned by (\text{Billy}) (i.e. (a+1 \le i \le a+b)), all successors lie in ({1,\dots,a}). Every node has at least one successor.
outputFormat
Output Format:
Output a single line containing the indices of all starting nodes for which (\text{Ann}) has a winning strategy. The indices should be output in increasing order, separated by a space. If there are no winning starting nodes, output an empty line.
sample
2 2
G 2 3 4
W 1 3
W 2 1 2
W 1 2
</p>