Codeforces 937D - Sleepy Game
思路:
dfs。
vis[u][0]==1表示u这个点能从s点偶数路径到达
vis[u][1]==1表示u这个点能从s点奇数路径到达
这个样就能保证dfs时每个点最多被访问2次
那么如果存在一个点u,vis[u][1]==1且u的出度为0,那么就存在能Win的方案
否则,dfs染色判环,如果存在从s点出发的环,就存在Draw的方案
不然就是Lose
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e5+;
vector<int>g[N],vc;
int vis[N][],pre[N][],vs[N];
void dfs(int o,int u,int d){
if(vis[u][d]==)return ;
vis[u][d]=;
pre[u][d]=o;
for(int i=;i<g[u].size();i++){
dfs(u,g[u][i],d^);
}
}
bool hasloop(int u){
vs[u]=;
bool f=false;
for(int i=;i<g[u].size();i++){
if(vs[g[u][i]]==)f=true;
else if(vs[g[u][i]]==)f=hasloop(g[u][i]);
if(f)return true;
}
vs[u]=;
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,m,t,u,s;
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>t;
while(t--){
cin>>u;
g[i].pb(u);
}
}
cin>>s;
dfs(,s,);
for(int i=;i<=n;i++){
if(vis[i][]&&g[i].size()==){
int u=i,t=;
vc.pb(u);
while(pre[u][t]!=){
vc.pb(pre[u][t]);
u=pre[u][t];
t^=;
}
cout<<"Win"<<endl;
for(int j=vc.size()-;j>=;j--)cout<<vc[j]<<' ';
cout<<endl;
return ;
}
}
if(hasloop(s))cout<<"Draw"<<endl;
else cout<<"Lose"<<endl;
return ;
}
Codeforces 937D - Sleepy Game的更多相关文章
- CodeForces 937D 936B Sleepy Game 有向图判环,拆点,DFS
题意: 一种游戏,2个人轮流控制棋子在一块有向图上移动,每次移动一条边,不能移动的人为输,无限循环则为平局,棋子初始位置为$S$ 现在有一个人可以同时控制两个玩家,问是否能使得第一个人必胜,并输出一个 ...
- Codeforces 937 D. Sleepy Game(DFS 判断环)
题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...
- Codeforces 937.D Sleepy Game
D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #467 (Div. 1) B. Sleepy Game
我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...
- Sleepy Game CodeForces - 936B
大意: 给定有向图, 初始点S, 两个人轮流移动, 谁不能移动则输, 但后手睡着了, 先手可以控制后手操作, 求最后先手结果. 刚开始看错了, 还以为后手也是最优策略.... 实际上判断是否有偶数个节 ...
- Codeforces 390A( 模拟题)
Inna and Alarm Clock Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题
A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...
- Codeforces Round #467 (div.2)
Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- P3369 【模板】普通平衡树(splay)
P3369 [模板]普通平衡树 就是不用treap splay板子,好好背吧TAT #include<iostream> #include<cstdio> #include&l ...
- linux command wrap
$ cat tmux-attach ] ; then tmux ls else tmux attach -t $ fi $ cat /usr/bin/cscope-go.sh #!/bin/bash ...
- Linux基础笔记—— 走进Linux
走进Linux 操作系统 操作系统是计算机中必不可少的基础系统软件,他的作用是管理和控制计算机系统中的硬件和软件资源,合理有效的组织系统的工作流程,在计算机系统(硬件)与使用者之间提供接口作用. 操作 ...
- answerOpenCV轮廓类问题解析
contour在opencv中是一个基础的数据结构,灵活运用的话,作用很大.以contour为关键字,在answerOpenCV中能够发现很多有趣的东西. 1.无法解决的问题 http://answe ...
- Codeforces 438D The Child and Sequence - 线段树
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...
- Python3 tkinter基础 Canvas background 创建白色的画布 create_line width 画宽的线
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- RabbitMQ 入门指南——初步使用
MQ的消息持久化 https://www.rabbitmq.com/tutorials/tutorial-two-java.html When RabbitMQ quits or crashes it ...
- linux基础之程序包管理(rpm,yum)
一.rpm 安装:rpm { -i | --install } [ install-options ] PACKAGE_FILE... -v: 显示安装时的详细信息 -vv: 显示许多难以阅读的调试信 ...
- .NET 介绍
In order to continue our effort of being modular and well factored we don’t just provide the entire ...
- Python数据类型补充2
四.列表 常用操作+内置的方法: 1.按索引存取值(正向存取+反向存取):即可存也可以取 # li=['a','b','c','d'] # print(li[-1]) # li[-1]='D' # p ...