连通图模板(HDU 1269)
http://acm.hdu.edu.cn/showproblem.php?pid=1269
题目大意:给定一个图,判断该图是否是强连通图。(强连通图为从任意一点出发,可到达其他所有点)。深搜的Tarjin算法即可通过。其中
判断是否为强连通图需要判断所给的图是否连成一块儿,并且连接次数为n(所有点都可连接)。
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stack>
#include <vector>
using namespace std;
#define N 10100
int Instack[N], dfn[N], low[N], block, cnt, Time, Top, my_Stack[N];
vector<vector<int> >G;
int n, m;
void Tra(int u)
{
dfn[u] = low[u] = ++Time;
Instack[u] = ;
my_Stack[Top++] = u;
int len = G[u].size(), v;
for(int i=; i<len; i++)
{
v = G[u][i];
if(!dfn[v])
{
Tra(v);
low[u] = min(low[u], low[v]);
}
else if(Instack[v])
low[u] = min(low[u], dfn[v]);
}
if(low[u]==dfn[u])
{
block++;
do
{
cnt++;
v = my_Stack[--Top];
Instack[v] = ;
}while(u!=v);
}
}
void Init()
{
memset(dfn, , sizeof(dfn));
memset(Instack, , sizeof(Instack));
memset(low, , sizeof(low));
memset(my_Stack, , sizeof(my_Stack));
G.clear();
G.resize(n+);
block = cnt = Time = Top = ;
}
int main()
{
while(scanf("%d %d", &n, &m), m+n)
{
int a, b;
Init();
for(int i=; i<=m; i++)
{
scanf("%d %d", &a, &b);
G[a].push_back(b);
}
Tra();
if(block== && cnt==n)printf("Yes\n");
else printf("No\n");
}
return ;
}
连通图模板(HDU 1269)的更多相关文章
- HDU 1269 迷宫城堡(强连通)
HDU 1269 迷宫城堡 pid=1269" target="_blank" style="">题目链接 题意:中文题 思路:强连通模板题 代 ...
- HDU 1269 迷宫城堡 (Kosaraju)
题目链接:HDU 1269 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000), ...
- Hdu 1269 强连通判定
题目链接 迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- fft模板 HDU 1402
// fft模板 HDU 1402 #include <iostream> #include <cstdio> #include <cstdlib> #includ ...
- hdu 1269 求连通图的模板题
#include<stdio.h> #include<string.h> #include<iostream>//只存在一个连通分量 #include<str ...
- 有向图强连通分支的Tarjan算法讲解 + HDU 1269 连通图 Tarjan 结题报告
题目很简单就拿着这道题简单说说 有向图强连通分支的Tarjan算法 有向图强连通分支的Tarjan算法伪代码如下:void Tarjan(u) {dfn[u]=low[u]=++index//进行DF ...
- 【无聊放个模板系列】HDU 1269 (SCC)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- HDU 1269 -- 迷宫城堡【有向图求SCC的数目 && 模板】
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- (连通图 模板题)迷宫城堡--hdu--1269
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1269 http://acm.hust.edu.cn/vjudge/contest/view.action ...
随机推荐
- Win7打补丁以后vs2012突然出现的程序版本不兼容问题
装这个: Update for Microsoft Visual Studio 2012 (KB2781514) http://www.microsoft.com/en-us/download/det ...
- [JBoss] - JBAS015874: JBoss AS 7.1.1.Final "Brontes" started - Eclipse中不能正常启动的解决方法
在使用Eclipse + Jboss插件时,如果有时写配置文件写错,在重新启动发布JBoss时,会出现: 14:43:49,317 INFO [org.jboss.as] (Controller B ...
- 基于Spring框架的Shiro配置
一.在web.xml中添加shiro过滤器 <!-- Shiro filter--> <filter> <filter-name>shiroFilter</ ...
- CSS基本语法
这里主要介绍Bootstrap里用到的CSS语法,以便在源码分析时更容易理解和学习.Bootstrap的CSS组件的核心就是选择器的定义以及在各自优先级上的处理. 优先级 如何确定CSS的优先级,这里 ...
- Tomcat 配置 HTTPS双向认证
Tomcat 配置 HTTPS 双向认证指引说明: � 本文档仅提供 Linux 操作系统下的指引 � 在阅读本指引前请您在 Linux 部署 JDK 和 Tomcatserver为了 Tomcat ...
- java maven诡异的错误no class found
从服务器下载一个java web项目,启动老提示no class found,查看maven依赖库,相关的jar包都已经引入.同样一个项目,在别的机器都可以运行,唯独在我本机运行出错. 为了排错,将其 ...
- buildbot的codebaseGenerator
buildbot的codebaseGenerator文档非常简单,简单到令人发指. 也没有一个例子,唉,辛苦了好几个小时才研究清楚怎么设置. 赶紧记录下吧,不然下次又要纠结. 应用场景:web sta ...
- How to configure Veritas NetBackup (tm) to write Unified and Legacy log files to a different directory
Problem DOCUMENTATION: How to configure Veritas NetBackup (tm) to write Unified and Legacy log files ...
- 19. Palindrome Partitioning && Palindrome Partitioning II (回文分割)
Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...
- GTD一些问题
一."大局"与事物的本质1,在处理每天.每小时的事务时,有很多干扰因素分散了我们的注意力,以致我们无法集中足够的精力关注更重要的问题.2,一种下意识的抵触情绪,在面对那些原本棘手的 ...