题意简述:给出一个有向图,问从s出发是否能找到一条长度为奇数的路径并且路径的端点出度为0,存在就输出路径,如果不存在判断图中是否存在环,存在输出Draw,否则输出lose

题解:类似于DP,将每一个点拆成两个点,d[x][0]=1表示存在一条s到x存在一条长度为奇数的路径,d[x][1]相反,然后正常bfs计算就好了

判环什么的都是小意思

#include<bits/stdc++.h>
#define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
#define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x) cout<<it<<endl;
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int maxm=2e5+5;
const int inf=1e9;
int n,m,s;
vector<int> g[maxn],ig[maxn];
int d[maxn][2],pre[maxn][2],vis[maxn];
bool dfs(int x){
vis[x]=1;
for(auto y:g[x])
if(vis[y]==1 || dfs(y)) return 1;
vis[x]=2;
return 0;
}
int main(){
cin>>n>>m;
queue<pair<int,int>> q;
for(int i=1;i<=n;i++){
int x=i,y;
int cc;
cin>>cc;
while(cc--){
cin>>y;
g[x].push_back(y);
ig[y].push_back(x);
}
if(g[x].size()==0) q.push({x,1});
}
while(q.size()){
pii x=q.front();q.pop();
for(auto y:ig[x.fi]){
if(d[y][x.se^1]==0) {
d[y][(x.se)^1]=1;
pre[y][(x.se)^1]=x.fi;
q.push({y,(x.se)^1});
}
}
}
cin>>s;
if(d[s][0]){
puts("Win");
vector<int> ans;
ans.push_back(s);
int p=s,px=0;
while(pre[p][px]){
p=pre[p][px],px^=1;
ans.push_back(p);
}
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<' ';
cout<<"\n";
}
else {
if(dfs(s)) puts("Draw");
else puts("Lose");
} }

  

cf936B的更多相关文章

随机推荐

  1. ios--->NSNotificationCenter传值

    object实现 //在发送通知时设置object参数 [[NSNotificationCenter defaultCenter] postNotificationName:@"ThisIs ...

  2. mysql--->profile使用

    Mysql分析-profile详解 简介 Profiling是从 mysql5.0.3版本以后才开放的. 启动profile之后,所有查询包括错误的语句都会记录在内. 此工具可用来查询SQL执行状态, ...

  3. codeforces 1278F - Cards(第二类斯特林数+二项式)

    传送门 解题过程: \(答案=\sum^n_{i=0}*C^i_n*{\frac{1}{m}}^i*{\frac{m-1}{m}}^{n-i}*i^k\) 根据第二类斯特林数的性质\(n^k=\sum ...

  4. BeautifulSoup标签定位方法总结

    首先说明一下两个基本函数 .find() 和 .findAll(). find()返回第一个符合要求的标签 findAll()返回一个由所有符合要求的标签组成的列表.除此之外基本相同. 0.直接定位 ...

  5. Spring初识、新建工程

    1.spring与三层架构的关系: spring负责管理项目中的所有对象,是一个一站式的框架,容器中的对象决定了spring的功能. 2.spring核心架构 Spring框架主要由六个模块组成,在开 ...

  6. 使用alpine制作最小化的JDK基础镜像

    注意:这里使用的是oracle的JRE,版本是1.8. 1.解压jre包,删除根目录下文本文件,然后删除其他不必要文件. #解压 tar xvcf jre-8u161-linux-x64.tar.gz ...

  7. LUAMD5加密

    md5里的方法: C:\Windows\System32>lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > require( ...

  8. Codeforces_723_A

    http://codeforces.com/problemset/problem/723/A 取中间那个数就可以了,答案为最大值减最小值. #include<iostream> #incl ...

  9. Codeforces 1175F The Number of Subpermutations (思维+rmq)

    题意: 求区间[l, r]是一个1~r-l+1的排列的区间个数 n<=3e5 思路: 如果[l,r]是一个排列,首先这里面的数应该各不相同,然后max(l,r)应该等于r-l+1,这就能唯一确定 ...

  10. 《Python学习手册 第五版》 -第7章 字符串基础

    本章内容是关于字符串的,字符串是编程中经常遇到的问题,本章的内容不是包含所有字符串的讲解,而是针对其最基本的内容进行说明,后续的相关章节会根据需要进行扩展和说明,例如后续的第37章内容会讲解Unico ...