#include<bits/stdc++.h>
using namespace std;#definedbdouble#definelllonglong#definePirpair<int,int>#definefifirst#definesesecond#definepbpush_back#definem_pmake_pair#defineinf0x3f3f3f3f#defineINF0x3f3f3f3f3f3f3f3f/*==========ACMer===========*/constint N =2005, M =6005;int n, m, k;structEdge{int v, ne;} e[M];int h[N], tot;voidadd(int u,int v){ e[++ tot]={ v, h[u]}; h[u]= tot;}int a[N], f[N];intsg(int u){if(f[u]!=-1)return f[u];
set<int> s;for(int i = h[u]; i; i = e[i].ne){int v = e[i].v;
s.insert(sg(v));}for(int i =0;; i ++){if(s.count(i)==0)return f[u]= i;}}intmain(){memset(f,-1,sizeof f);scanf("%d %d %d",&n,&m,&k);int u, v;while(m --){scanf("%d %d",&u,&v);add(u, v);}for(int i =1; i <= k; i ++)scanf("%d",&a[i]);int ans =0;for(int i =1; i <= k; i ++) ans ^=sg(a[i]);if(ans)printf("win\n");elseprintf("lose\n");return0;}
思路n 个图是 n 个独立的游戏,我们可以求每个图的 sg 值异或起来,等于 0 必败否则必胜。代码#include <bits/stdc++.h>using namespace std;#define db double#define ll long long#define Pir pair<int, int>#define fi first#define se second#define pb push_back#define m_p ma.