我一开始把题目看错了 我以为是博弈。。

这题就是一个简单的判环+dfs(不简单,挺烦的一题)

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
const int N = 2e5 + 5; struct GraphNode {
int toVertex, nextPoint;
} GraphTable[N];
int headOfVertex[N];
bool visitedVertex[N][2];
int visitedCircle[N];
class Graph {
private:
int startVertex_;
int totEdge_;
int hasCircle_;
int hasSuccess_;
std::vector<int> ansPath;
bool dfsGraph(int vertex, int step) {
if (headOfVertex[vertex] == -1) {
// printf("%d %d\n", vertex, headOfVertex[vertex]);
return step & 1;
}
for (int i = headOfVertex[vertex]; ~i; i = GraphTable[i].nextPoint) {
int toVertex = GraphTable[i].toVertex;
if (!visitedVertex[toVertex][step]) {
visitedVertex[toVertex][step] = true;
bool hasSuccess = dfsGraph(toVertex, step ^ 1);
if (hasSuccess) {
ansPath.push_back(toVertex);
// printf("to %d\n", toVertex);
return true;
}
}
}
return false;
}
bool judgeCircle(int vertex) {
visitedCircle[vertex] = -1;
for (int i = headOfVertex[vertex]; ~i; i = GraphTable[i].nextPoint) {
int toVertex = GraphTable[i].toVertex;
if (visitedCircle[toVertex] == 0) {
bool flag = judgeCircle(toVertex);
if (flag)
return true;
visitedCircle[toVertex] = 1;
} else if (visitedCircle[toVertex] == -1)
return true;
}
return false;
} public:
Graph() {
ansPath.clear();
totEdge_ = 0;
hasSuccess_ = false;
hasCircle_ = false;
memset(visitedVertex, 0, sizeof(visitedVertex));
memset(visitedCircle, 0, sizeof(visitedCircle));
memset(headOfVertex, -1, sizeof(headOfVertex));
}
void setStartVertex(int startVertex) { startVertex_ = startVertex; }
void addEdge(int fromVertex, int toVertex) {
// printf("%d %d\n", fromVertex, toVertex);
GraphTable[totEdge_].toVertex = toVertex;
GraphTable[totEdge_].nextPoint = headOfVertex[fromVertex];
headOfVertex[fromVertex] = totEdge_++;
}
void solve() {
visitedVertex[startVertex_][1] = true;
hasCircle_ = judgeCircle(startVertex_);
hasSuccess_ = dfsGraph(startVertex_, 0); if (hasSuccess_) {
ansPath.push_back(startVertex_);
reverse(ansPath.begin(), ansPath.end());
printf("Win\n");
for (int i = 0; i < ansPath.size(); ++i)
printf("%d ", ansPath[i]);
printf("\n");
} else if (hasCircle_)
printf("Draw\n");
else
printf("Lose\n");
}
}; int main() {
int n, m;
while (~scanf("%d %d", &n, &m)) {
Graph Basa = Graph();
for (int i = 1; i <= n; ++i) {
int numberOfEdge;
scanf("%d", &numberOfEdge);
for (int j = 0; j < numberOfEdge; ++j) {
int toVertex;
scanf("%d", &toVertex);
Basa.addEdge(i, toVertex);
}
}
int startVertex;
scanf("%d", &startVertex);
Basa.setStartVertex(startVertex);
Basa.solve();
}
return 0;
}

Codeforces Round #467 (Div. 1) B. Sleepy Game的更多相关文章

  1. Codeforces Round #467 (div.2)

    Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...

  2. Codeforces Round #467 (Div. 2) B. Vile Grasshoppers

    2018-03-03 http://codeforces.com/problemset/problem/937/B B. Vile Grasshoppers time limit per test 1 ...

  3. Codeforces Round #467 Div.2题解

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces Round #467 (Div. 1). C - Lock Puzzle

    #include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...

  5. Codeforces Round #467 Div. 1

    B:显然即相当于能否找一条有长度为奇数的路径使得终点出度为0.如果没有环直接dp即可.有环的话可以考虑死了的spfa,由于每个点我们至多只需要让其入队两次,复杂度变成了优秀的O(kE).事实上就是拆点 ...

  6. Codeforces Round #467 (Div. 2) E -Lock Puzzle

    Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...

  7. Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]

    B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #467 (Div. 2) A. Olympiad[输入一组数,求该数列合法的子集个数]

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. vue-router 二级路由

    /** * Created by 我 on 2017/12/4. */ import Vue from 'vue' //import导入 Vue(自己起的名) from 从 vue import Vu ...

  2. iconfont 怎么在项目中使用图标库

    iconfont是很多设计以及前后端人员编写页面时经常用到的网站,阿里不仅为我们提供了免费的图标库,并且有一套完整的图标库体系.很多初学者只知道从图标库中下载图标放入项目中,但在实际项目应用中,过多的 ...

  3. Python中的浅拷贝与深拷贝

    编者注:本文主要参考了<Python核心编程(第二版)> 以下都是参考资料后,我自己的理解,如有错误希望大家不吝赐教. 大家有没有遇到这样一种情况,对象赋值后,对其中一个变量进行修改,另外 ...

  4. 树莓派3B上部署运行.net core 2程序

    针对Linxu arm处理器如何部署.net core 2的资料很少,网上找到几篇但都写得不够详细,按照他们教程来撞墙了,折磨了几天终于部署成功了,先上一张运行成功的图 1.windows系统中,在项 ...

  5. Redis 学习(一) —— 安装、通用key操作命令

    一.Redis介绍 1.介绍 通常,在系统中,我们会把数据交由数据库来存储,但传统的数据库增删查改的性能较差,且比较复杂.根据 80/20 法则,百分之八十的业务访问集中在百分之二十的数据上.是否可以 ...

  6. Js比较对Object类型进行排序

    <script> var data=[{name:"121",age:"18",year:"2018"},{name:" ...

  7. Maven中的pom.xml详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  8. GCD实现倒计时

    之前面试中,好多面试官,问使用GCD如何实现倒计时,我当时也没写过,所以一时不知道怎么说,所以结束之后,我实现一下GCD的倒计时. - (void)startTime:(UIButton *)send ...

  9. 2018/3/2晚11点30分写的程序(C++)

    程序目标:输入一个字符串,竖向输出该字符串.使用string和动态分配内存机制.代码如下: #include<iostream>#include "stdafx.h"# ...

  10. Angular CurrencyPipe货币管道关于人民币符号¥的问题

    做项目(Angular项目)时经常需要处理金额的显示,需要在金额前面加上¥,但又不想用简单在前面加"¥"这么不优雅的方式,于是想到了CurrencyPipe.毕竟,Currency ...