Test instructions
Alice and Bob play a game on a map, each individual operation of a pawn, if the two pieces go to a point, Judge Bob to lose; if the turn of any party, can not move the pieces, determine the party loses
Now Bob goes first and asks for a verdict.
Exercises
The model is the SG problem, but the usual SG practice requires DP, but considering that this is not a DAG model, ordinary memory search notation will re
DP Practice of positive solution: Dp[i][j][k]:i,j is the position of Bob,alice, K is the current turn who is gone.
Start by adding all of the obvious bob losses to the queue and expanding to find all of Bob's losses.
Transfer similar to SG
#include <bits/stdc++.h>#defineCLR (x, Y) memset ((×), (y), sizeof (x))using namespaceStd;typedefLong LongLL;Const intmaxn= -;structnode{intx1,x2; intTurn//0:bob 1:alice};intn,m;intb;intnum[maxn+5][maxn+5];intdeg[maxn+5];BOOLmp[maxn+5][maxn+5];BOOLdp[maxn+5][maxn+5][2];queue<Node>Q;voidSolveinticase) { while(!Q.empty ()) Q.pop (); intu,v; CLR (MP,0); CLR (deg,0); for(intI=1; i<=m;++i) {scanf ("%d%d",&u,&v); ++Deg[u]; MP[U][V]=true; } scanf ("%d%d",&a,&b); CLR (DP,-1); for(intI=1; i<=n;++i) {dp[i][i][0]=false; dp[i][i][1]=false; Q.push (Node) {i,i,0}); Q.push (Node) {i,i,1}); } for(intI=1; i<=n;++i) {if(deg[i]==0) { for(intj=1; j<=n;++j) {if(I==J)Continue; dp[i][j][0]=false; Q.push (Node) {i,j,0}); }}} clr (num,0); while(!Q.empty ()) {Node now=Q.front (); Q.pop (); intx1=now.x1; intX2=now.x2; intturn=Now.turn; if(turn==0) { for(intI=1; i<=n;++i) {if(mp[i][x2]) {if(!dp[x1][i][1])Continue; dp[x1][i][1]=false; Q.push (Node) {x1,i,1}); } } } Else { for(intI=1; i<=n;++i) {if(Mp[i][x1]) {++NUM[I][X2]; if(Num[i][x2]==deg[i])//if all states starting from I are required to fail, then dp[i][x2][0] itself is a must-fail state. { if(!dp[i][x2][0])Continue; dp[i][x2][0]=false; Q.push (Node) {i,x2,0}); } } } } } if(dp[a][b][0]) printf ("Case #%d:yes\n", icase); Elseprintf"Case #%d:no\n", icase);}intMainvoid) {#ifdef ex freopen (".. /in.txt","R", stdin); //freopen (".. /out.txt "," w ", stdout); #endif intT; scanf ("%d",&T); for(intI=1; i<=t;++i) {scanf ("%d%d",&n,&m); Solve (i); }}
Codeforce Gym 100548H The problem to make you Happy