迷宫城堡--HDOJ 1269(Tarjan)
迷宫城堡
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5732 Accepted Submission(s): 2543
1 2
2 3
3 1
3 3
1 2
2 3
3 2
0 0
/*=====================================================================
# Author: wangzhili
# Mail : wangstdio.h@gmail.com
# QQ : 240130760
# Filename: tarjan.c
# Last modified: 2013-12-06 09:18
=====================================================================*/ #include<stdio.h>
#include<string.h>
typedef struct
{
int to;
int next;
}EdgeNode;
EdgeNode edge[];
int dfn[],low[];
int head[],vis[];
int stack[];
int top,ind,cnt,n,m;
int min(int x,int y)
{
return x < y ? x : y;
} void tarjan(int i)
{
int j,v;
dfn[i] = low[i] = ++ind;
stack[++top] = i;
vis[i] = ;
for(j = head[i]; j != -;j = edge[j].next)
{
v = edge[j].to;
if(!dfn[v])
{
tarjan(v);
low[i] = min(low[i],low[v]);
}
else if(vis[v])
low[i] = min(low[i],dfn[v]);
}
if(dfn[i] == low[i])
{
cnt ++;
do
{
j = stack[top--];
vis[j] = ;
}while(j != i);
}
}
void solve()
{
int i;
cnt = ;
top = ind = ;
memset(dfn,,sizeof(dfn));
memset(vis,,sizeof(vis));
for(i = ;i <= n;i ++)
{
if(!dfn[i])
tarjan(i);
}
return ;
} int main()
{
int i,j;
int a,b;
freopen("in.c","r",stdin);
while(~scanf("%d%d",&n,&m) && (m+n))
{
memset(head,-,sizeof(head));
for(i = ;i < m;i ++)
{
scanf("%d%d",&a,&b);
edge[i].to = b;
edge[i].next = head[a];
head[a] = i;
}
solve();
if(cnt == )
printf("Yes\n");
else
printf("No\n");
}
return ;
}
迷宫城堡--HDOJ 1269(Tarjan)的更多相关文章
- 迷宫城堡--HDOJ 1269
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDOJ迷宫城堡(判断强连通 tarjan算法)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 迷宫城堡 HDU - 1269 判断有向图是否是强连通图
为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A房间和B房间,只说明可以 ...
- HDU 1269 迷宫城堡(强连通)
HDU 1269 迷宫城堡 pid=1269" target="_blank" style="">题目链接 题意:中文题 思路:强连通模板题 代 ...
- hdoj 1269 迷宫城堡【scc基础题目】
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1269 迷宫城堡(判断有向图强连通分量的个数,tarjan算法)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1269 迷宫城堡(向量)(Tarjan模版题)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1269.迷宫城堡-Tarjan or 双向DFS
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1269 迷宫城堡 (tarjan)
迷宫城堡Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- java.lang.NoSuchMethodError: org.apache.neethi.Policy.normalize(Z)Lorg/apache/neethi/PolicyComponent
记录一个org.apache.neethi包的异常 java.lang.NoSuchMethodError: org.apache.neethi.Policy.normalize(Z)Lorg/apa ...
- Oracle的安装
本人所使用的数据库平台为Oracle 11g 1.下载Oracle Oracle官网即可下载Oracle平台.不过网上资源丰富,大家也可在百度云网盘找到合适的版本. 附上本人网盘里存储的各个Oracl ...
- leetcode345——Reverse Vowels of a String(C++)
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- ilasm.exe与ildasm.exe的使用(编译与反编译)
ilasm.exe与ildasm.exe的使用(编译与反编译) 首先打开cmd命令.cd 到 C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0 ...
- docker中搭建gitlab
1, 下载镜像 docker pull sameersbn/gitlab:7.4.3 # 下载gitlab镜像 docker pull sameersbn/mysql:latest # 下载gitla ...
- php 加载函数 __autoload(), spl_autoload_register()
来自:http://www.cnblogs.com/myluke/archive/2011/06/25/2090119.html spl_autoload_register (PHP 5 >= ...
- web 中 bbs 例子(多次递归)
数据库设计:create table `header`( // 父表 parent int not null, //父级 poster varchar(20) not null, //作者 p ...
- MySQL字符串中数字排序的问题
1.select * from table where 1 order by id*1 desc; 2.select * from table where 1 order by id+0 desc ...
- Python开发之--前端 HTML基础
一:HTML介绍 HTML:超文本标记语言,标准通用标记语言下的一个应用.包括"头"部分(英语:Head).和"主体"部分(英语:Body),其中"头 ...
- RabbitMQ PHP操作类,守护进程及相关测试数据
封装类如下: <?php /* * amqp协议操作类,可以访问rabbitMQ * 需先安装php_amqp扩展 */ class RabbitMQCommand{ public $confi ...