Reprinted please indicate the source, thank youHttp://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.
# 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-7using 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 ;}