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 ...
随机推荐
- ubuntu - sudo in php exec
最近写防火墙的WEB版,需要在PHP中调用linux系统命令,但是防火墙有关的执行都需要管理员权限才能执行. 在ubuntu下,Apache2的运行账户默认是www-data,默认是不能通过sudo来 ...
- windows azure programing
http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-get-started-vs2012/ http:// ...
- python mongodb MapReduce
# -*- coding: utf-8 -*-import osimport csvimport pymongofrom pymongo import MongoClientfrom bson.cod ...
- css中table-layout:fixed 属性的用法
table-layout:fixed 属性的用法:如果想要一个table固定大小,里面的文字强制换行(尤其是在一长串英文文本,并且中间无空格分隔的情况下),以达到使过长的文字 不撑破表格的目的,一般是 ...
- SecureCRT+WinSCP 共用 key pub 密钥 转换 ppk 登录ssh
使用SecureCRT生成的密钥,无法在WinSCP使用, 使用puttygen.exe无法直接转换,解决办法 1.使用大于等于SecureCRT6.5版本,来转换 记得放入私钥,不是pub公钥.然后 ...
- codeforces 390C Inna and Candy Boxes
这个题目看似不是很好下手,不过很容易发现每次询问的时候总是会问到第r个盒子是否有糖果: 这样的话就很好办事了: 维护两个数组: 一个sum数组:累加和: 一个in数组:如果i位是1的话,in[i]=i ...
- 对话 Jessica Hamrick:和 Django 的情缘是我前行的动力
本文出自 Your Django Story 系列,该系列主要突出那些贡献 Django 的女性.点击查看更多,本文系 OneAPM 工程师编译整理. Jess Hamrick 是加州大学伯克利分校心 ...
- tortoisesvn的安装与使用
1.下载安装文件,我用的是1.6.同时可以下载一个中文的安装包. 2.我在F盘建立了一个文件夹tortoisesvn,专门用来放置版本目录文件.然后右键这个文件夹,选择tortoisesvn-> ...
- MySQL性能调优与架构设计-架构篇
架构篇(1) 读书笔记 1.Scale(扩展):从数据库来看,就是让数据库能够提供更强的服务能力 ScaleOut: 是通过增加处理节点的方式来提高整体处理能力 ScaleUp: 是通过增加当前处理节 ...
- laravel code bright
Project RootLet’s start by taking a look at the root folder structure.• app/• bootstrap/• vendor/• p ...