大意: 给定有向图, 初始点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 '\n'
#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");
}

最新文章

  1. canvas画圆(一)
  2. 开源MVCPager
  3. Gremlins.js – 模拟用户随机操作的 JS 测试库
  4. PHP语言基础(标记、注释、变量、数组、常量、函数)
  5. 关于最大流的EdmondsKarp算法详解
  6. debug.keystore文件不存在解决办法
  7. [Angualr 2] Watch for changes
  8. jQuery读取json文件,实现省市区/县(国标)三级联动
  9. sql中select语句的逻辑执行顺序
  10. Linux双网卡NAT共享上网
  11. JSP编译为Java类
  12. ecshop的aes加密(封装)
  13. iframe之局部刷新
  14. nginx 反向代理,支持跨域,前后分离
  15. Python练手例子(12)
  16. 第4章 打包和构建 - Identity Server 4 中文文档(v1.0.0)
  17. Pandas模块
  18. django~项目的文件位置的重要性
  19. where 命令
  20. idea ssm项目出现日志中文乱码,封装的json中的msg字段中文乱码(但是json封装的bean中的字段不乱码)等其他各种项目下的中文乱码解决方案

热门文章

  1. 黑马lavarel教程---12、lavarel验证码
  2. Error in render: &quot;TypeError: Cannot read property &#39;url_img&#39; of undefined&quot;
  3. leetcode334 递增的三元子序列
  4. C代码调用Java代码
  5. three中的着色器示例
  6. LCTF (easyeasy-200)
  7. R数据分析(一)
  8. 语音识别LD3320
  9. Leetcode之广度优先搜索(BFS)专题-752. 打开转盘锁(Open the Lock)
  10. 关于SQL关键字&quot;having &quot;