大意: 给定有向图, 初始点S, 两个人轮流移动, 谁不能移动则输, 但后手睡着了, 先手可以控制后手操作, 求最后先手结果.
刚开始看错了, 还以为后手也是最优策略.... 实际上判断是否有偶数个节点的路径即可, 每个点拆成奇数跟偶数, 这样图就是一个DAG, 可以DP求出路径, 若不存在的话找一下是否有环, 有环则平局, 无环则输.
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #include <bitset> #define REP(i,a,n) for(int i=a;i<=n;++i) #define PER(i,a,n) for(int i=n;i>=a;--i) #define hr putchar(10) #define pb push_back #define lc (o<<1) #define rc (lc|1) #define mid ((l+r)>>1) #define ls lc,l,mid #define rs rc,mid+1,r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl ' ' #define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;}) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int P = 1e9+7, INF = 0x3f3f3f3f; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;} ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;} //head #ifdef ONLINE_JUDGE const int N = 1e6+10; #else const int N = 111; #endif int n, m, ok, dp[2][N], fa[2][N], inq[N]; vector<int> g[N]; int dfs(int tp, int x) { if (ok) return 0; if (g[x].empty()&&tp==0) return ok=1; if (dp[tp][x]) return 0; dp[tp][x] = 1; for (int y:g[x]) if (dfs(tp^1,y)) return fa[tp][x]=y; return 0; } int dfs(int x) { inq[x] = 1; for (int y:g[x]) if (inq[y]||dfs(y)) return inq[x]=0,1; return inq[x] = 0; } int main() { scanf("%d%d", &n, &m); REP(i,1,n) { int k, t; scanf("%d", &k); REP(j,1,k) scanf("%d", &t),g[i].pb(t); } int s; scanf("%d", &s); if (dfs(1,s)) { puts("Win"); int now = 1; while (s) printf("%d ", s), s=fa[now][s],now^=1; return hr,0; } puts(dfs(s)?"Draw":"Lose"); }