【无聊放个模板系列】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 ...
随机推荐
- 几种RAID技术比较
http://book.51cto.com/art/201310/412862.htm RAID(廉价磁盘冗余阵列)技术主要是为了改善磁盘的访问延迟,增强磁盘的可用性和容错能力.目前服务器级别的计算机 ...
- 误解了Windows Server AppFabric
想为自己的流程引擎找一个宿主,选择了几套方案,想先从AppFabric开始,原因主要出于以下几点: 1. 自己用过Windows Service或Form作为一些定时任务等应用的宿主,但苦于学艺不精, ...
- python出现Non-ASCII character '\xe7' in file ex6.py on line 1, but no encoding declare错误
http://www.cnblogs.com/qi09/archive/2012/02/06/2340712.html python中出现Non-ASCII character '\xe7' in f ...
- sql 更新重复数据只取一条记录
select s.* from ( select *, row_number() over (partition by PersonnelAccount order BY Personnel ...
- iOS UIView 快速修改 frame,
在iOS开发布局修改 frame 时需要繁琐的代码实现,今天偶尔看到一播客说到快速修改的 frame 的方法,自己动手写了一遍实现代码. 快速实现主要通过 添加类目的方式,对UIView 控件添加了一 ...
- Java架构必会几大技术点(转)
关于学习架构,必须会的几点技术: 1. java反射技术 2. xml文件处理 3. properties属性文件处理 4. 线程安全机制 5. annocation注解 6. 设计模式 7. 代理机 ...
- javaee学习-新建servlet 直接返回html
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...
- nodejs学习[持续更新]
1.退出node process.exit(0) 2.把API从上往下全部看一遍,先混个眼熟. 3. end
- 在Linux系统下安装大于mysql5.5版本的数据库
linux下mysql 5.5的安装方法: 1.安装所需要系统库相关库文件 gcc等开发包,在安装linux系统的时候安装. 2.创建mysql安装目录 # mkdir -p /usr/lo ...
- php configure help
`configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION].. ...