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 ...
随机推荐
- 人民币大写金额转换C#方法
方法的代码如下: /// <summary> /// 人民币大写 /// </summary> /// <param name="input"> ...
- EF工作中踩过的坑.
1.EF同一个linq里边不支持两个或两个以上不同dbcontext的使用,必须拆解开才能使用; ef也不支持自定义集合和dbcontext属性的混合使用. 2.如果要用用统一域账号连接databas ...
- C# ICSharpCode.SharpZipLib.dll文件压缩和解压功能类整理,上传文件或下载文件很常用
工作中我们很多时候需要进行对文件进行压缩,比较通用的压缩的dll就是ICSharpCode.SharpZipLib.dll,废话不多了,网上也有很多的资料,我将其最常用的两个函数整理了一下,提供了一个 ...
- jquery function Optional Arguments
1.javascript 选项散列对象 function Test(p1,p2,p3,p4,p5){ //do something } call: 参数可选 Test({ p1:value1, p2: ...
- 编写运行R脚本
1.在后台运行R 1.1 创建file.R文件 1.2 在文件首行键入: #! /path/to/Rscript 1.3 在下面的行中,键入R代码 1.4 保存(记得有png(),jpeg(),... ...
- 设计模式之Builder (创建者模式)的一些个人理解(转)
对于Builder模式很简单,但是一直想不明白为什么要这么设计,为什么要向builder要Product而不是向知道建造过程的Director要.刚才google到一篇文章,总算清楚了.在这里转贴一下 ...
- 【翻译】Netscaler真实表现性能调整
源地址:https://msandbu.wordpress.com/2014/10/31/netscaler-and-real-performance-tuning/ 作者显然不是以英语为母语的,所以 ...
- 初学Node(三)模块系统
模块系统 Node根据CommonJS规范实现了一套自己的模块机制,可以使用require()导入一个模块,使用module.exports导出一个模块. require使用 在Node中我们可以使用 ...
- SAP中的Currency Converting Factor
ABAP编程中,有个概念很重要,即Currency Converting Factor(货币转换因子).可能很多ABAP初学者都不知道这是什么东西,这里我们就简单探讨下. 1. 什么是货币转换因子 在 ...
- English Training Material - 02
OUTSIDE CORRESPONDENCE AND CONTACT Jared: I'm glad you could come – and you're in for a treat. Thi ...