poj 1144 Network 图的割顶判断模板
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8797 | Accepted: 4116 |
Description
each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is
possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that
in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure
occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.
Input
to which there is a direct line from this place. These at most N lines completely describe the network, i.e., each direct connection of two places in the network is contained at least in one row. All numbers in one line are separated
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;
Output
Sample Input
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
1
2
Hint
//题意,给一个图,求图中割顶的个数~~~
#include "stdio.h" //poj 1144 割顶的判断模板
#include "vector"
#include "string.h"
using namespace std; #define N 105
vector<int> a[N];
int root;
int low[N],dfn[N];
bool visit[N],mark[N];
int MIN(int x,int y) { return x<y?x:y; } void DFS(int x,int times)
{
int i;
int count = 0;
visit[x] = true;
low[x] = dfn[x] = times;
for(i=0; i<a[x].size(); ++i)
{
int y = a[x][i];
if(!visit[y])
{
count++;
DFS(y,times+1);
low[x] = MIN(low[x],low[y]);
if(x==root && count==2) mark[root] = true; //如果x为根节点,并且子树有两个或两个以上,则为割顶!
if(x!=root && low[y]>=dfn[x]) mark[x] = true; //如果x的子树中没有节点连接x的祖先(有的话low[x]会变小),则为割顶!
}
else
low[x] = MIN(low[x],dfn[y]);//更新low[x]的值!
}
} int main()
{
int n;
int i,j;
char ch;
while(scanf("%d",&n),n!=0)
{
int x,y;
for(i=0; i<N; ++i)
a[i].clear();
while(scanf("%d",&x),x!=0)
{
while(scanf("%c",&ch) && ch==' ')
{
scanf("%d",&y);
a[y].push_back(x);
a[x].push_back(y);
}
}
root = 1;
int times = 1;
memset(mark,false,sizeof(mark)); //标记点是否是割顶
memset(visit,false,sizeof(visit)); //标记点是否已访问 DFS(root,times);
int ans = 0;
for(i=1; i<=n; ++i)
{
if(mark[i]) ans++; //统计割顶个数
}
printf("%d\n",ans);
}
return 0;
}
poj 1144 Network 图的割顶判断模板的更多相关文章
- poj 1144 Network(无向图求割顶数)
题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...
- POJ 1144 Network(无向图的割顶和桥模板题)
http://poj.org/problem?id=1144 题意: 给出图,求割点数. 思路: 关于无向图的割顶和桥,这篇博客写的挺不错,有不懂的可以去看一下http://blog.csdn.net ...
- 图论(无向图的割顶):POJ 1144 Network
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. ...
- POJ 1144 Network【割顶】
学习的这一篇:https://www.byvoid.com/blog/biconnect 割顶:对于无向图G,如果删除某个点u后,连通分量数目增加,称u为图的关节点或者割顶 u为割顶的条件: (1)u ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- POJ1144 Network 无向图的割顶
现在打算重新学习图论的一些基础算法,包括像桥,割顶,双连通分量,强连通分量这些基础算法我都打算重敲一次,因为这些量都是可以用tarjan的算法求得的,这次的割顶算是对tarjan的那一类算法的理解的再 ...
- POJ 1144 Network(无向图连通分量求割点)
题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...
- POJ 1144 Network (求割点)
题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...
随机推荐
- dp - 2015 Multi-University Training Contest 2 1004 Delicious Apples
Delicious Apples Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5303 Mean: 一条长为L的环形路上种着n棵 ...
- 组合数学 - 母函数的运用 --- hdu 1709 :The Balance
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Winform开发框架之客户关系管理系统(CRM)的开发总结系列3-客户分类和配置管理实现
我在本系列随笔的开始,介绍了CRM系统一个重要的客户分类的展示界面,其中包含了从字典中加载分类.从已有数据中加载分类.以及分组列表中加载分类等方式的实现,以及可以动态对这些节点进行配置,实现客户分类的 ...
- 如何修改myeclipse 内存?eclipse.ini中各个参数的作用。
修改MyEclipse/eclipse文件夹中配置文件eclipse.ini中的内存分配就哦了 =================================== 一般的ini文件设置主要包括以下 ...
- C#基础--之数据类型
C#基础--之数据类型 摘自:http://www.cnblogs.com/tonney/archive/2011/03/18/1987577.html 在第一章我们了解了C#的输入.输出语句后,我这 ...
- SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈【转】
转载自:http://blog.csdn.net/dba_huangzj/article/details/7607844#comments 通过DMV查看当时SQL SERVER所有任务的状态(sle ...
- Win7如何部署apache服务器(包括SSL设置)
部署普通站点 1.首先下载apache24版本,下载地址为http://pan.baidu.com/s/1pLmvDgB; 2.解压到你的电脑本地目录,如D:\Apache24(下文配置都会以当前目录 ...
- 【JS复习笔记】02 对象与函数
好吧,因为很重要的事情,几天没写笔记了. 关于对象: ||可以用来填充默认值,如:myApp.name || "无" &&可以用来避免错误,myApp.NameOb ...
- OAuth2.0 基础概述
web:http://oauth.net/2/ rfc:http://tools.ietf.org/html/rfc6749 doc:http://oauth.net/documentation/ c ...
- DP入门---Robberies
HDU 2955 Description The aspiring Roy the Robber has seen a lot of American movies, and knows that ...