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

这题就是一个简单的判环+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. SpringMVC源码情操陶冶-AbstractUrlHandlerMapping

    承接前文SpringMVC源码情操陶冶-AbstractHandlerMapping,前文主要讲解了如何获取handler处理对象,本文将针对beanName注册为handler对象作下解析 Abst ...

  2. CenOS 上安装 Redis 服务器

    1.构建 Redis 因为 Redis 官方没提供 RPM 安装包,所以需要编译源代码,则需要安装 GCC & MAKE. 终端输入: yum install gcc make 从官网下载 t ...

  3. 微信小程序开发《一》:阿里云tomcat免费配置https

    小狼咕咕最近开启了微信小程序开发的征程,由于微信小程序的前后台通信必须通过https协议,所以小狼咕咕第一件要做的事就是配置一个能够通过https访问的后台服务.小狼咕咕用的是阿里云ECS服务器,Li ...

  4. 微信小程序项目踩过的几个坑

    一.前言 近期,开始了一段辛酸的还未开始就已经结束的"创业"(参见我的第二次创业,以梦为马,莫负韶华).大体上是开发了一款微信小程序,关于创业这件事情就不细说了,本文主要介绍一下开 ...

  5. OpenLayer3调用天地图,拖拽后,地图消失的问题[已解决]

    拖拽后,地图直接消失了,而且右上角的坐标变成了NaN,NaN 后来经过测试发现,原来是自己封装有问题,坐标点一定要用parseFloat()转换下,但不清楚为什么页面刚开始加载的时候没有问题,总之能解 ...

  6. [Python Study Notes]匿名函数

    Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...

  7. Java经典编程题50道之四十

    将几个字符串排序(按英文字母的顺序). public class Example40 {    public static void main(String[] args) {        Stri ...

  8. PHP文件头BOM头问题

    前几天我们公司服务器出现了一个离奇的问题,服务器与本地文件代码完全一致,本地运行正常,到了测试环境服务器之后,各种问题一个又一个浮现,先是后台验证码不显示,以为是session写入失败,又是怀疑gd库 ...

  9. PHP如何防止XSS攻击

    PHP防止XSS跨站脚本攻击的方法:是针对非法的HTML代码包括单双引号等,使用htmlspecialchars()函数 . 在使用htmlspecialchars()函数的时候注意第二个参数, 直接 ...

  10. 校验Linux程序是否被黑客修改

    一个黑客突破你的层层防御后,修改你的程序或者覆盖了你的工具时.确定一个已安装程序的所有文件,有没有被修改过的途径之一就是使用RPM包校验功能 如果图片排版有任何错误,欢迎访问我的简书www.jians ...