【无聊放个模板系列】HDU 1269 (SCC)
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
#define Maxn 10010
#define Maxm 100010 struct node
{
int x,y,next;
}t[Maxm];int len;
int first[Maxn]; void ins(int x,int y)
{
t[++len].x=x;t[len].y=y;
t[len].next=first[x];first[x]=len;
} int mymin(int x,int y) {return x<y?x:y;} int dfn[Maxn],low[Maxn],cnt,scc;
stack<int > s;
bool inst[Maxn]; void dfs(int x,int f)
{
dfn[x]=low[x]=++cnt;
inst[x]=;s.push(x);
for(int i=first[x];i;i=t[i].next) if(t[i].y!=f)
{
int y=t[i].y;
if(dfn[y]==)
{
dfs(y,x);
low[x]=mymin(low[x],low[y]);
}
else if(inst[y]) low[x]=mymin(low[x],dfn[y]);
}
if(low[x]==dfn[x])
{
int z;scc++;
while()
{
z=s.top();s.pop();
inst[z]=;
if(z==x) break;
}
}
} int main()
{
while()
{
int n,m;
scanf("%d%d",&n,&m);
if(n==&&m==) break;
len=;
memset(first,,sizeof(first));
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ins(x,y);
}
cnt=;scc=;
memset(dfn,,sizeof(dfn));
memset(inst,,sizeof(inst));
for(int i=;i<=n;i++) if(dfn[i]==) dfs(i,);
if(scc==) printf("Yes\n");
else printf("No\n");
}
return ;
}
SCC
2016-11-17 20:56:27
【无聊放个模板系列】HDU 1269 (SCC)的更多相关文章
- 【无聊放个模板系列】HDU 3506 (四边形不等式优化DP-经典石子合并问题[环形])
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】HDU 1358 KMP
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】HDU 3068 MANACHER
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】BZOJ 3172 (AC自动机)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】BZOJ 1597 斜率优化
STL 双向队列DEQUE版本 #include<cstdio> #include<cstdlib> #include<cstring> #include<i ...
- 【无聊放个模板系列】POJ 3678 2-SAT
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】POJ 1274 (匈牙利)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 【无聊放个模板系列】POJ2752 EXKMP
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 连通图模板(HDU 1269)
http://acm.hdu.edu.cn/showproblem.php?pid=1269 题目大意:给定一个图,判断该图是否是强连通图.(强连通图为从任意一点出发,可到达其他所有点).深搜的Tar ...
随机推荐
- JavaScript 一个等号 两个等号 三个等号的区别
一个等号 =:表示赋值 : 两个等号 ==:先转换类型再比较 : 三个等号 ===:先判断类型,如果不是同一类型直接false.
- 基于spark实现表的join操作
1. 自连接 假设存在如下文件: [root@bluejoe0 ~]# cat categories.csv 1,生活用品,0 2,数码用品,1 3,手机,2 4,华为Mate7,3 每一行的格式为: ...
- webform处理过程
一.post/get传值注意几点 post提交的时候,只有写了name属性且没有写disable=true表单元素(input,select,textarea)才会被提交. 如果不确定是get还是po ...
- Sophos UTM WebAdmin存在未明漏洞
...
- 批量杀进程——xargs用途
ps -ef|grep ora|grep “LOCAL=YES”|awk ‘{print $2}’|xargs –I {} kill -9 {} ps -ef|grep ora|grep “LOCAL ...
- javascript 第27节 jQuery选择器
下面的html需要以下2个文件: 1.style.css div,span,p { width:140px; height:140px; margin:5px; background:#aaa; bo ...
- 一篇关于学C++的感想(拿来与大家分享)
学计算机的如果你有耐心看下去,我敢保证这绝对是一种收获 期待爱 大师提醒: 计算机专业不是学编程,而是懂得计算机的工作原理,以及和计算机相关的学科技术.一个高手不必懂得编程,coder是最底层的人物, ...
- Java实战之04JavaWeb-08文件上传与下载
一.文件上传 1.文件上传的实质是什么 文件的拷贝,文件从客户端拷贝服务器端 2.文件上传的工作 (1)客户端怎样将本地文件输出去? 1)文件上传的表单项 <input type=”file”& ...
- 软件测试之 LoadRunner安装\破解\汉化
一.下载 LoadRunner下载地址:http://kuai.xunlei.com/d/QRNIUASALOIE 二. 安装 1.启动安装程序 运行setup.exe,点击“LoadRunner完整 ...
- jtemplate使用笔记
最近的项目中用到了jtemplate, 它是客户端基于javascript的模板引擎,绑定的数据为json对象.以前我在页面上显示数据列表时最喜欢用Repeater控件了,因为它相对与其它几个服务端控 ...