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. HTML的代码规范

    一.语法 用两个空格来代替制表符(tab) 2.嵌套元素应当缩进一次(即两个空格). 3.对于属性的定义,确保全部使用双引号,绝不要使用单引号. 4.不要省略可选的结束标签(例如,</li> ...

  2. Yii 之components

    当我们创建一个module的时候,对应的path alias就已经创建.比如我们定义了一个module: www 1 2 3 4 5 'modules'=>array(     'www'=&g ...

  3. 【代码笔记】iOS-cell折叠

    一,效果图. 二,工程图. 三,代码. AppDelegate.h #import <UIKit/UIKit.h> //加入头文件 #import "myQQView.h&quo ...

  4. windows如何查看nvidia显卡(GPU)的利用率和温度

    windows如何查看nvidia显卡(GPU)的利用率和温度 nvidia-smi 只要在文件夹C:\Program Files\NVIDIA Corporation\NVSMI里找到文件nvidi ...

  5. Python 3从入门到精通02-python的简单使用

    Python 3中的打印语句和字符串使用: Python中的常见数学运算: 这样的简单基础知识,你需要花5分钟就可以了,很基础的东西.

  6. Aheadof Time Compilation(AOT) vs (JIT)Just In Time compilation approach

    像java这样的高级语言,往往先做好部分编译,在运行时,再使用JIT将前面编译的中间件输出编译为机器语言,放到机器上运行.这可能会影响到运行的性能. 再比如,像angular的web 应用,angul ...

  7. 通过windows powershell 修改 Office 365默认的 35MB 的邮件大小限制

    附件下载: 通过windows powershell 修改 Office 365默认的 35MB 的邮件大小限制

  8. Vue2学习笔记:键盘事件

    Vue2键盘事件:keydown/keyup... 1.使用 <!DOCTYPE html> <html> <head> <title></tit ...

  9. [CENTOS7] 加入Windows域

    This following article is a snapshot from: https://www.rootusers.com/how-to-join-centos-linux-to-an- ...

  10. springboot 针对jackson是自动化配置

    spring.jackson.date-format指定日期格式,比如yyyy-MM-dd HH:mm:ss,或者具体的格式化类的全限定名 spring.jackson.deserialization ...