poj 1144 Network【双连通分量求割点总数】
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 11042 | Accepted: 5100 |
Description
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
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>
#include<string.h>
#include<stack>
#include<algorithm>
#define MAX 1100
#define MAXM 2000100
#define INF 0x7fffff
using namespace std;
struct node
{
int beg,end,next;
}edge[MAXM];
int low[MAX],dfn[MAX];
int head[MAX],ans;
int dfsclock;
int iscut[MAX];
void init()
{
ans=0;
memset(head,-1,sizeof(head));
}
void add(int u,int v)
{
edge[ans].beg=u;
edge[ans].end=v;
edge[ans].next=head[u];
head[u]=ans++;
}
void tarjan(int u,int fa)
{
int v,i;
low[u]=dfn[u]=++dfsclock;
int son=0;
for(i=head[u];i!=-1;i=edge[i].next)
{
v=edge[i].end;
if(!dfn[v])
{
son++;
tarjan(v,u);
low[u]=min(low[u],low[v]);
if(u!=fa&&dfn[u]<=low[v])
iscut[u]=1;
}
else
low[u]=min(dfn[v],low[u]);
}
if(fa==u&&son>1)
iscut[u]=1;
}
void find(int l,int r)
{
memset(low,0,sizeof(low));
memset(dfn,0,sizeof(dfn));
memset(iscut,0,sizeof(iscut));
dfsclock=0;
for(int i=l;i<=r;i++)
{
if(!dfn[i])
tarjan(i,i);
}
}
int main()
{
int n,m,j,i,t;
int a,c,len;
char b;
char s[5010];
while(scanf("%d",&n),n)
{
init();
int sum=0; while(scanf("%d", &a), a)
{
while(getchar() != '\n')
{
scanf("%d", &c);
add(a,c);
add(c,a);
}
} // while(scanf("%d",&a),a) 我真的搞不懂我这个输入错在哪里一直wa
// {
// while(scanf("%c",&b)&&b!='\n')
// {
// c=b-'0';
// add(a,c);
// add(c,a);
// }
// } find(1,n);
for(i=1;i<=n;i++)
{
if(iscut[i])
sum++;
}
printf("%d\n",sum);
}
return 0;
}
poj 1144 Network【双连通分量求割点总数】的更多相关文章
- POJ 1144 Network(无向图连通分量求割点)
题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- POJ 1144 Network(tarjan 求割点个数)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17016 Accepted: 7635 Descript ...
- poj 1144 Network(无向图求割顶数)
题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
- C++[Tarjan求点双连通分量,割点][HNOI2012]矿场搭建
最近在学图论相关的内容,阅读这篇博客的前提是你已经基本了解了Tarjan求点双. 由割点的定义(删去这个点就可使这个图不连通)我们可以知道,坍塌的挖煤点只有在割点上才会使这个图不连通,而除了割点的其他 ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- POJ 2117 Electricity 双联通分量 割点
http://poj.org/problem?id=2117 这个妹妹我竟然到现在才见过,我真是太菜了~~~ 求去掉一个点后图中最多有多少个连通块.(原图可以本身就有多个连通块) 首先设点i去掉后它的 ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...
随机推荐
- 异步IO模型和Overlapped结构
.NET中的 Overlapped 类 异步IO模型和Overlapped结构(http://blog.itpub.net/25897606/viewspace-705867/) 数据结构 OVERL ...
- 关于\t
tail -n 10000 sample_dbl.txt | python sitemap.py | sort -k 1 -t $'\t' | python sitecombiner.py > ...
- SQL 中With as 的用法
转自:http://www.cnblogs.com/superyinhai/archive/2010/04/09/1708643.html 一.WITH AS的含义 WITHAS短语,也叫做子查询部分 ...
- linux下如何安装rzsz
1, 下载包: wget http://freeware.sgi.com/source/rzsz/rzsz-3.48.tar.gz 2, 解压缩:tar -zxvf rzsz-3.48.tar.gz ...
- TSS 内核栈 用户栈的关系
http://blog.sina.com.cn/s/blog_673ef8130100qaje.html 该博客不错,有不少有用的信息 中断程序的一开始我们执行一个PUSHALL,把这些积存器保存在核 ...
- ANDROID_MARS学习笔记_S01原始版_014_WIFI
一.代码1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayo ...
- Android Service的生命周期
service的生命周期,从它被创建开始,到它被销毁为止,可以有两条不同的路径: A started service 被开启的service通过其他组件调用 startService()被创建. 这种 ...
- VC多文档编程技巧(取消一开始时打开的空白文档)
VC多文档编程技巧(取消一开始时打开的空白文档) http://blog.csdn.net/crazyvoice/article/details/6185461 VC多文档编程技巧(取消一开始时打开的 ...
- Spring AOP实现方式三之自动扫描注入【附源码】
注解AOP实现 这里唯一不同的就是application 里面 不需要配置每个bean都需要配置了,直接自动扫描 注册,主要知识点是怎么通过配置文件得到bean, 注意类前面的@注解. 源码结构: ...
- 【HDOJ】1045 Fire Net
经典深搜.注意满足条件. #include <stdio.h> #include <string.h> #define MAXNUM 5 char map[MAXNUM][MA ...