HDU1269 迷宫城堡
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!
Sample Input
1 2
2 3
3 1
3 3
1 2
2 3
3 2
0 0
Sample Output
No
//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
int n,m,ecnt,first[MAXN],to[MAXM],NEXT[MAXM];
int dfn[MAXN],low[MAXN],cnt,zhan[MAXN],top;
bool pd[MAXN]; inline int getint(){
int w=,q=; char c=getchar(); while((c<''||c>'') && c!='-') c=getchar();
if(c=='-') q=,c=getchar(); while (c>=''&&c<='') w=w*+c-'',c=getchar(); return q?-w:w;
} inline void tarjan(int x){
dfn[x]=low[x]=++ecnt; zhan[++top]=x; pd[x]=;
for(int i=first[x];i;i=NEXT[i]) {
int v=to[i];
if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
else if(pd[v]) low[x]=min(low[x],dfn[v]);
}
if(dfn[x]==low[x]) {
cnt++; while(zhan[top]!=x) pd[zhan[top]]=,top--;
pd[x]=; top--;
}
} inline void work(){
while() {
n=getint(); m=getint(); int x,y; if(n== && m==) break;
memset(first,,sizeof(first)); ecnt=;
for(int i=;i<=m;i++) { x=getint(); y=getint(); NEXT[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; }
memset(dfn,,sizeof(dfn)); memset(low,,sizeof(low)); ecnt=;
cnt=; for(int i=;i<=n;i++) if(!dfn[i]) tarjan(i);
if(cnt!=) printf("No\n"); else printf("Yes\n");
}
} int main()
{
work();
return ;
}
HDU1269 迷宫城堡的更多相关文章
- HDU1269迷宫城堡(裸Tarjan有向图求强连通分量个数)
迷宫城堡Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU1269 迷宫城堡 2016-07-24 13:47 84人阅读 评论(0) 收藏
迷宫城堡 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的 ...
- HDU1269 迷宫城堡 —— 强连通分量
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1269 迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU-1269 迷宫城堡(连通分量)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU1269 迷宫城堡(裸强连通分量)
Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A ...
- hdu1269迷宫城堡 (强连通Tarjan+邻接表)
Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每一个通道都是单向的,就是说 ...
- hdu1269迷宫城堡(判断有向图是否是一个强连通图)
1 /* 题意: 给你一个图,求这个有向图示否是一个强连通图(每两个节点都是可以相互到达的)! 思路1:按正向边dfs一遍,将经过的节点计数,如果记录的节点的个数小于n,那么就说明图按照正向边就不是连 ...
- [hdu1269]迷宫城堡(SCC)
题意:求一张图的强连通分量,若为1,则输出yes,否则输出no. 解题关键:targin算法模板题. #include<iostream> #include<cstring> ...
- HD1269迷宫城堡(有向图 && 划分连通块)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
随机推荐
- git 解决fatal: Not a git repository
我用git add file添加文件时出现这样错误: fatal: Not a git repository (or any of the parent directories): .git 提示说没 ...
- 正在编译转换: 未能找到元数据文件 EntityFramework.dll
错误 1 正在编译转换: 未能找到元数据文件“C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\..\IDE\Enti ...
- IE 和Firefox的js兼容性总结
IE 和Firefox的js兼容性总结 12 August 2010 11:39 Thursday by 小屋 标签: 浏览器 方法 属性 IT 写法 一.函数和方法差异 1 . getYear()方 ...
- eclipse/intellij idea 远程调试hadoop 2.6.0
很多hadoop初学者估计都我一样,由于没有足够的机器资源,只能在虚拟机里弄一个linux安装hadoop的伪分布,然后在host机上win7里使用eclipse或Intellj idea来写代码测试 ...
- mac:在当前文件夹打开terminal终端
System Preferences -> Keyboard -> Shortcuts -> Services -> New Terminal at Folders/New T ...
- python 测试驱动开发的简单例子
一.需求分析 需求:一个类 MyClass,有两个功能:add, sub 1.先功能设计 # myclass.py class MyClass(object): # 加法 def add(self): ...
- 基于DDD的.NET开发框架 - ABP启动配置
返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应 ...
- .Net分布式异常报警系统-服务端Service
服务端的2个Service 1. HandleService: 从Redis中获取异常信息, 入库并发送通知到相关责任人. 2. HealthyCheckService: 对站点指定页面进行模拟访问 ...
- Common Issues Which Cause Roles to Recycle
This section lists some of the common causes of deployment problems, and offers troubleshooting tips ...
- 基于FPGA的音频信号的FIR滤波(Matlab+Modelsim验证)
1 设计内容 本设计是基于FPGA的音频信号FIR低通滤波,根据要求,采用Matlab对WAV音频文件进行读取和添加噪声信号.FFT分析.FIR滤波处理,并分析滤波的效果.通过Matlab的分析验证滤 ...