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 ...
随机推荐
- cocos2dx3.4 保存json文件
头文件: #include "json/document.h" #include "json/stringbuffer.h" #include "js ...
- 关于c++字符串的while(*temp++)
首先,上一段代码 static bool reverse_str(const char *str) { const char *temp=str; while(*temp++); temp-=; // ...
- C++ 数据类型及相关问题 及输出精度控制
1.有哪些数据类型? 2.数据类型在不同的编译器会有不同的位宽,如何得知? 使用如下命令: cout<<sizeof(int)<<endl; cout<<sizeo ...
- sjtu1585 oil
Description Crystal家的公司最近承包了一个大油田.整块油田为一个矩形区域,被划分为\(n \times m\)个小块. Crystal亲自调查了每个小块的石油储备量.这些数据表示为\ ...
- MongoDB开发应用实战
http://special.csdn.net/mongodb/ http://www.csdn.net/article/2011-03-21/294271 http://blog.itpub.net ...
- su: /bin/bash: Permission denied
https://bbs.archlinux.org/viewtopic.php?id=105541 New user created as: groupadd mygroupuseradd -s /b ...
- Tomcat 6 支持 NIO -- Tomcat的四种基于HTTP协议的Connector性能比较(转载)
Tomcat从5.5版本开始,支持以下四种Connector的配置分别为: <Connector port="8081" protocol="org.apache. ...
- MMU、Icache、Dcache
http://blog.csdn.net/iodoo/article/details/8954014 i-cache(instruction cache)是指令高速缓冲存储器. Cache存储体:存放 ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER003_播放mp3
一.简介 1.在onListItemClick中实现点击条目时,跳转到PlayerActivity,mp3info通过Intent传给PlayerActivity 2.PlayerActivity通过 ...
- PLSQL操作
游标 SQL> set serveroutput onSQL> DECLARE 2 --定义游标,因为该游标中的数据需要更新,所以使用for update 3 CURSOR ...