http://codeforces.com/problemset/problem/936/B

Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't move the chip loses. If the game lasts for 106 turns the draw is announced.

Vasya was performing big laboratory work in "Spelling and parts of speech" at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya's and Vasya's moves.

Your task is to help Petya find out if he can win the game or at least draw a tie.

Input

The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).

The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and cidistinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ nai, j ≠ i).

It is guaranteed that the total sum of ci equals to m.

The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).

Output

If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, ..., vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1... k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.

If Petya can't win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».

Examples
input

Copy
5 6
2 2 3
2 4 5
1 4
1 5
0
1
output
Win
1 2 4 5
input

Copy
3 2
1 3
1 1
0
2
output
Lose
input

Copy
2 2
1 2
1 1
1
output
Draw
Note

In the first example the graph is the following:

Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.

In the second example the graph is the following:

Initially the chip is located at vertex 2. The only possible Petya's move is to go to vertex 1. After that he has to go to 3 for Vasya. Now it's Petya's turn but he has no possible move, so Petya loses.

In the third example the graph is the following:

Petya can't win, but he can move along the cycle, so the players will draw a tie.

这题很坑,还是我太弱了,套路太浅

1.这种图论问奇偶数的问题,一定要考虑奇环的存在(走一个奇环可以改变路径的奇偶)(就是这个地方让我一直TLE,mmp)

  所以呢,打标记数组改成vis[maxn][2](用上^1),且就是为了防止重复走不必要的一个顶点,此题的dfs回溯不需要清空vis!!!

2.判环的存在这题就直接过程中book掉就好,不过也要去看看tarjan算法(算环的个数)

http://blog.csdn.net/qq_34374664/article/details/77488976

3.判出度为0的学到可以新开一个chu[]存(这样看起来舒服),不用head[u]==0这种,且链式前向星存图注意顶点为0的情况时需要初始化为-1

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int maxn = 2e5 + ;
// name*******************************
struct edge
{
int to,next;
} e[maxn];
int tot=;
int head[maxn];
int n,m,s;
int book[maxn];
int vis[maxn][];
int chu[maxn];
int res[maxn];
int cnt=;
int flag=;
// function******************************
void add(int u,int v)
{
tot++;
e[tot].to=v;
e[tot].next=head[u];
head[u]=tot;
}
void dfs(int u,int mk)
{
for(int p=head[u]; p; p=e[p].next)
{
int v=e[p].to;
// cout<<"u:"<<u<<" v:"<<v<<" cnt:"<<cnt<<" flag:"<<flag<<" mk:"<<(mk^1)<<endl;
if(book[v])flag=;
book[v]=;
if(vis[v][mk^])continue;
vis[v][mk^]=;
res[++cnt]=v;
if(!chu[v]&&!mk)
{
cout<<"Win"<<endl;
For(i,,cnt)
{
cout<<res[i]<<" ";
}
exit();
}
dfs(v,mk^);
book[v]=;
cnt--;
}
} //***************************************
int main()
{
ios::sync_with_stdio();
cin.tie();
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin>>n>>m;
For(i,,n)
{
int t;
cin>>t;
chu[i]=t;
For(j,,t)
{
int x;
cin>>x;
add(i,x);
}
}
cin>>s;
book[s]=;
res[++cnt]=s;
dfs(s,);
if(flag)
cout<<"Draw";
else
cout<<"Lose"; return ;
}

B. Sleepy Game的更多相关文章

  1. 树状数组 || 线段树 || Luogu P5200 [USACO19JAN]Sleepy Cow Sorting

    题面:P5200 [USACO19JAN]Sleepy Cow Sorting 题解: 最小操作次数(记为k)即为将序列倒着找第一个P[i]>P[i+1]的下标,然后将序列分成三部分:前缀部分( ...

  2. Codeforces 937D - Sleepy Game

    937D - Sleepy Game 思路: dfs. vis[u][0]==1表示u这个点能从s点偶数路径到达 vis[u][1]==1表示u这个点能从s点奇数路径到达 这个样就能保证dfs时每个点 ...

  3. Codeforces 937 D. Sleepy Game(DFS 判断环)

    题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...

  4. Codeforces 937.D Sleepy Game

    D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. LG5200 「USACO2019JAN」Sleepy Cow Sorting 树状数组

    \(\mathrm{Sleepy Cow Sorting}\) 问题描述 LG5200 题解 树状数组. 设\(c[i]\)代表\([1,i]\)中归位数. 显然最终的目的是将整个序列排序为一个上升序 ...

  6. P5200 [USACO19JAN]Sleepy Cow Sorting

    P5200 [USACO19JAN]Sleepy Cow Sorting 题目描述 Farmer John正在尝试将他的N头奶牛(1≤N≤10^5),方便起见编号为1…N,在她们前往牧草地吃早餐之前排 ...

  7. C Sleepy Kaguya

    链接:https://ac.nowcoder.com/acm/contest/338/C来源:牛客网 题目描述 Houraisan☆Kaguya is the princess who lives i ...

  8. Sleepy与DbgHlp库学习

    参考:http://msdn.microsoft.com/en-us/library/windows/desktop/ms679291(v=vs.85).aspx http://msdn.micros ...

  9. UVa 10427 - Naughty Sleepy Boys

    题目大意:从1开始往后写数字,构成一个如下的字符串 123456789101112... .求第n位的数字是多少. 找规律,按数字的位数可以构建一个类似杨辉三角的东西,求出第n位是哪个数的第几位即可. ...

  10. Codeforces Round #467 (Div. 1) B. Sleepy Game

    我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...

随机推荐

  1. 转:PHP导出excel文件的几种方式

    PHP导出excel文件的几种方式 文章来源:http://www.cnblogs.com/fredshare/archive/2012/10/29/2744243.html 先说说动态生成的内容当作 ...

  2. Git——远程操作详解

    转载自:http://www.ruanyifeng.com/blog/2014/06/git_remote.html 作者: 阮一峰 日期: 2014年6月12日 Git是目前最流行的版本管理系统,学 ...

  3. React-Native开发之原生模块封装(Android)升级版

     本文主题:如何实现原生代码的复用,即如何将原生模块封装. (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/52862 ...

  4. node(6)angular介绍

    一.angular 的介绍 AngularJS[1]  诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中. ...

  5. 如何在定制化组件中实现并使用v-model

    https://alligator.io/vuejs/add-v-model-support/

  6. [C# | WinCE | Solution] 在 WinCE 上访问 SSL 加密后的 WCF SOAP 服务接口出现“未能与远程服务器建立信任关系”

    Scenario: 服务器的 SOAP 使用了 GeoTrust 签名的 EV 证书,WinCE调用时出现“未能与远程服务器建立信任关系”的错误.原因是该 WinCE 设备信任的证书包括 Global ...

  7. Jmeter入门--元件作用域和执行顺序

    一.元件作用域 8类可被执行的元件(测试计划于线程组不属于可执行元件),这些元件中,取样器(Sampler)是典型的不与其他元件发生交互作用的元件,逻辑控制器只对其子节点的取样器有效,而其他元件(配置 ...

  8. asp.net MVC 使用PagedList.MVC实现分页

    在上一篇的EF之DB First中,存在以下的两个问题: 1. 添加/编辑页面显示的是属性名称,而非自定义的名称(如:姓名.专业...) 2. 添加/编辑时没有加入验证 另外数据展示使用分页 @Htm ...

  9. [翻译] UIColor-uiGradientsAdditions

    UIColor-uiGradientsAdditions https://github.com/kaiinui/UIColor-uiGradientsAdditions Beautiful color ...

  10. 使用最新版SDWebImage

    使用最新版SDWebImage 1. 下载源码: 2. 测试能否编译成功: 3. 用Xcode6新建一个工程,然后将文件夹拖入到工程当中: 4. 查看其主要的源码,发现之前使用版本的方法都被弃用了: ...