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. CSS 高度(css height)

    DIV+CSS height高度知识教程篇 DIV CSS高度简介这里的CSS高度是指通过CSS来控制设置对象的高度.使用CSS属性单词height.单位可以使用PX,em等常用使用PX(像素)为ht ...

  2. android之在view中内嵌浏览器的方法

    我要做的一个东西是在一个页面的中间嵌入浏览器,一开始不知道从哪里开始,因为以前用的都是Textveiw或者editVeiw之类的控件,而它们并不能用来显示网页的内容,怎么办呢? 首先想到的是:是不是有 ...

  3. 以local模式使用Xshell+Xmanager远程监控jvisualvm

    使用jvisualvm的remote方式监控服务器端jvisualvm时,不是很方便,因此通过local方式,应该是正路. 一.服务器端(Linux,最小安装模式,没有图形界面) 1.安装xauth ...

  4. 一步一步 Pwn RouterOS之ctf题练手

    前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 本文目的是以一道比较简单的 ctf 的练手,为后面的分析 Rout ...

  5. 1.Spring——七大主要模块

    Spring有七大功能模块,分别是Spring Core,AOP,ORM,DAO,MVC,WEB,Content. 下面分别简单介绍: 1.Spring Core Core模块是Spring的核心类库 ...

  6. java笔记--线程休眠sleep()的运用

    线程休眠sleep()方法的运用 在多线程编程中,有时需要让某个线程优先执行.除了可以设置这个线程的优先级为最高外,更加理想的方法是休眠其他线程,若有线程中断了正在休眠的线程,则抛出Interrupt ...

  7. Oracle EBS 请求参数关联

  8. a标签 按钮化使用

    a标签 按钮化使用 a href="javascript:void(0);" onclick="js_method()" a href="javasc ...

  9. C# Redis的操作

    Nuget添加StackExchange.Redis的引用 由于Redis封装类同时使用了Json,需要添加JSON.NET引用(Newtonsoft.Json) Redis封装类 /// <s ...

  10. Linux 系统的/目录

    根目录下的重要目录 目录 应放置档案内容 /bin 系统有很多放置执行档的目录,但/bin比较特殊.因为/bin放置的是在单人维护模式下还能够被操作的指令.在/bin底下的指令可以被root与一般帐号 ...