Reprint please indicate the source, thank you http://blog.csdn.net/ACM_cxlove? Viewmode = contents by --- cxlove
This is a game against Directed Acyclic graphs.
Question: There are N locations in which there is a topological relationship, which must be observed when moving. Finally, the mobile app wins and asks if there is a winning strategy
Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1524
A directed acyclic graph. The SG function of a vertex is the smallest of its successor nodes. (MEX operation ).
It is the same as finding a common SG function.
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Define N 10005
# Define LL long
# Define inf 1 <29
# Define eps 1e-7
Using namespace std;
Vector <int> v [1005];
Int n, sg [1005];
Int get_sg (int n ){
If (sg [n]! =-1)
Return sg [n];
If (v [n]. size () = 0)
Return 0;
Int vis [1005];
Memset (vis, 0, sizeof (vis ));
For (int I = 0; I <v [n]. size (); I ++ ){
Sg [v [n] [I] = get_sg (v [n] [I]);
Vis [sg [v [n] [I] = 1;
}
For (int I = 0; I ++)
If (vis [I] = 0)
Return I;
}
Int main (){
While (scanf ("% d", & n )! = EOF ){
Memset (sg,-1, sizeof (sg ));
For (int I = 0; I <n; I ++ ){
V [I]. clear ();
Int k, u;
Scanf ("% d", & k );
While (k --){
Scanf ("% d", & u );
V [I]. push_back (u );
}
}
Int q, k, u;
While (scanf ("% d", & k ){
Int ret = 0;
While (k --){
Scanf ("% d", & u );
If (sg [u] =-1)
Sg [u] = get_sg (u );
Ret ^ = sg [u];
}
If (ret = 0)
Puts ("LOSE ");
Else
Puts ("WIN ");
}
}
Return 0;
}
By ACM_cxlove