[Cpp]
// HDOJ 1524 A Chess Game SG Function
/*
Question: There is a directed acyclic graph with stones at some points. These stones can be moved to the subsequent node each time.
Two people move in turn.
Idea: Create a graph to calculate the SG value for each vertex
*/
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Define N 1005
# Define M 1000005
Int n, m;
Int num, head [N];
Int in [N], out [N], sg [N];
Struct node {
Int from;
Int;
Int next;
} Edge [M];
Void addedge (int from, int ){
Edge [num]. from = from;
Edge [num]. to =;
Edge [num]. next = head [from];
Head [from] = num ++;
}
Void init (){
Num = 0;
Memset (head,-1, sizeof (head ));
Memset (sg,-1, sizeof (sg ));
}
Int mex (int n ){
Int I;
Bool vis [N];
If (sg [n]! =-1)
Return sg [n];
Memset (vis, false, sizeof (vis ));
For (I = head [n]; I! =-1; I = edge [I]. next ){
If (sg [edge [I]. to] =-1)
Sg [edge [I]. to] = mex (edge [I]. );
Vis [sg [edge [I]. to] = true;
}
For (I = 0; ++ I)
If (vis [I] = false)
Return I;
}
Int main (){
Int I, j, k, x, a, p;
While (scanf ("% d", & n )! = EOF ){
Init ();
For (I = 0; I <n; ++ I ){
Scanf ("% d", & m );
For (j = 0; j <m; ++ j ){
Scanf ("% d", & k );
Addedge (I, k );
}
}
While (scanf ("% d", & x), x ){
Int ans = 0;
For (I = 0; I <x; ++ I ){
Scanf ("% d", & );
Ans ^ = mex ();
}
Puts (ans? "WIN": "LOSE ");
}
}
Return 0;
}