题意略。

思路:

图论里掺杂了一些动态规划。

有几个注意点:

1.dp时状态的设计:因为我们要寻求的是出度为0并且可以从起点走奇数步抵达的点,由于同一个点可以通过多种方式到达。

并且我们在获得奇数步点的时候,需要偶数步点作为支撑,所以visit[ i ][ j ]表示第i个点能否具备j状态(0、1),也即奇偶数步。

2.dp采用spfa,也即刷表法。在使用spfa时,最好将点和状态一起打包。

3.判断有向图是否存在环,可以采用拓扑排序。

详见代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ; struct node{
int v,state;
node(int v = ,int state = ){
this->v = v;
this->state = state;
}
}; int visit[maxn][],out[maxn],indegree[maxn],n,m,s;
bool vis[maxn];
vector<int> graph[maxn],vs;
queue<node> que;
queue<int> topque; void spfa(){
memset(visit,,sizeof(visit));
visit[s][] = -;
que.push(node(s,));
while(que.size()){
node nd = que.front();
que.pop();
int v = nd.v,state = nd.state;
for(int i = ;i < graph[v].size();++i){
int u = graph[v][i];
if(!visit[u][state ^ ]){
visit[u][state ^ ] = v;
que.push(node(u,state ^ ));
}
}
}
}
bool judcircle(){
int cnt = ;
for(int i = ;i <= n;++i){
if(!visit[i][] && !visit[i][]) continue;
if(indegree[i] == )
topque.push(i);
++cnt;
}
while(topque.size()){
int v = topque.front();
topque.pop();
--cnt;
for(int i = ;i < graph[v].size();++i){
int u = graph[v][i];
indegree[u] -= ;
if(indegree[u] == ) topque.push(u);
}
}
return cnt > ;
}
void dfs(int cur){
for(int i = ;i < graph[cur].size();++i){
int v = graph[cur][i];
++indegree[v];
if(indegree[v] == ){
dfs(v);
}
}
} int main(){
scanf("%d%d",&n,&m);
memset(indegree,,sizeof(indegree));
for(int i = ,to;i <= n;++i){
scanf("%d",&out[i]);
for(int j = ;j < out[i];++j){
scanf("%d",&to);
graph[i].push_back(to);
}
}
scanf("%d",&s);
dfs(s);
spfa();
bool circle = judcircle();
bool jud = false;
for(int i = ;i <= n && !jud;++i){
if(!out[i] && visit[i][] != ){
jud = true;
printf("Win\n");
int now = ;
for(int v = i;v != -;v = visit[v][now],now = now ^ ){
vs.push_back(v);
}
for(int j = vs.size() - ;j >= ;--j){
printf("%d%c",vs[j],j ? ' ' : '\n');
}
}
}
if(!jud){
printf("%s\n",circle ? "Draw" : "Lose");
}
return ;
} /*
6 6
1 2
2 3 4
1 5
1 5
1 6
0
3
*/

Codeforces 936B的更多相关文章

  1. Sleepy Game CodeForces - 936B

    大意: 给定有向图, 初始点S, 两个人轮流移动, 谁不能移动则输, 但后手睡着了, 先手可以控制后手操作, 求最后先手结果. 刚开始看错了, 还以为后手也是最优策略.... 实际上判断是否有偶数个节 ...

  2. CodeForces 937D 936B Sleepy Game 有向图判环,拆点,DFS

    题意: 一种游戏,2个人轮流控制棋子在一块有向图上移动,每次移动一条边,不能移动的人为输,无限循环则为平局,棋子初始位置为$S$ 现在有一个人可以同时控制两个玩家,问是否能使得第一个人必胜,并输出一个 ...

  3. codeforces的dp专题

    1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 解密Kafka吞吐量高的原因

    众所周知kafka的吞吐量比一般的消息队列要高,号称the fastest,那他是如何做到的,让我们从以下几个方面分析一下原因. 生产者(写入数据) 生产者(producer)是负责向Kafka提交数 ...

  2. android 基于wifi模块通信开发

    这篇文章主要是我写完手机与wifi模块通信后所用来总结编写过程的文章,下面,我分几点来说一下编写的大概流程. 一.拉出按钮控件并设置它的点击事件 二.设置wifi权限 三.打开和关闭wifi 四.扫描 ...

  3. 计算机网络中IP地址和MAC地址

    计算机 网络中的网络地址有I P 地址和物理地址之分,对 于主机间的通信时,它们的作用也不一样 . l   I P 地址 为 了保证 I n t e r n e t 网上主机通信时能够相互识别 ,不引 ...

  4. codeforces 340 A. The Wall

    水水的一道题,只需要找xy的最小公倍数,然后找a b区间有多少个可以被xy的最小公倍数整除的数,就是答案. //============================================ ...

  5. 经典SQL(sqlServer)

    一.基础 .说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) .分组: ...

  6. Flink 从0到1学习—— 分享四本 Flink 国外的书和二十多篇 Paper 论文

    前言 之前也分享了不少自己的文章,但是对于 Flink 来说,还是有不少新入门的朋友,这里给大家分享点 Flink 相关的资料(国外数据 pdf 和流处理相关的 Paper),期望可以帮你更好的理解 ...

  7. sqoop 密码别名模式 --password-alias

    sqoop要使用别名模式隐藏密码 1.首先使用命令创建别名 hadoop credential create xiaopengfei  -provider jceks://hdfs/user/pass ...

  8. 微信分享(移动web端)

    create-at 2019-02-16 引入微信JS-SDK http://res.wx.qq.com/open/js/jweixin-1.4.0.js (当前最新版本) js 相关代码 (移动端实 ...

  9. mysql中防止sql注入

    什么是sql注入 图片来源:百度百科 python 操作mysql产生sql注入问题 不用ORM框架,框架中已经集成了防范sql注入的功能,使用pymysql实践一下: # 导入pymysql模块 i ...

  10. html5 placeholder属性兼容ie11

    placeholder 属性是html5的属性,用于提供描述输入字段预期值的提示信息(hint). 简单例子: <!DOCTYPE HTML> <html> <body& ...