Network
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17016   Accepted: 7635

Description

A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in 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

The input file consists of several blocks of lines. Each block describes one network. In the first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places 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

The output contains for each block except the last in the input file one line containing the number of critical places.

Sample Input

5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0

Sample Output

1
2

Hint

You need to determine the end of one line.In order to make it's easy to determine,there are no extra blank before the end of each line.

Source

 
分析:
好惭愧啊,现在才会求割点,学习了一个新的算法,tarjan算法,但现在只会用他来求割点和割边....
tarjan学习是参考的这位大佬的博客,写得真的简单易懂
 
code:
邻接矩阵实现:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
int mon1[]= {,,,,,,,,,,,,};
int mon2[]= {,,,,,,,,,,,,};
int dir[][]= {{,},{,-},{,},{-,}}; int getval()
{
int ret();
char c;
while((c=getchar())==' '||c=='\n'||c=='\r');
ret=c-'';
while((c=getchar())!=' '&&c!='\n'&&c!='\r')
ret=ret*+c-'';
return ret;
} #define max_v 1005
int dfn[max_v];
int low[max_v];
int vis[max_v];
int G[max_v][max_v]; int depth,n,m,root,rt_cnt; void init()
{
root=;
depth=;
rt_cnt=;
memset(dfn,-,sizeof(dfn));
memset(G,,sizeof(G));
memset(vis,,sizeof(vis));
memset(low,,sizeof(low));
} void tarjan(int cur,int pa)
{
dfn[cur]=low[cur]=depth++;
for(int i=;i<=n;i++)
{
if(G[cur][i])
{
if(dfn[i]==-)//i没有访问过
{
tarjan(i,cur);
low[cur]=min(low[cur],low[i]);//逐步回溯更新访问过的父节点的low if(cur==root)
rt_cnt++;//统计和根结点直接相连的点的个数,来确定根结点是不是割点
else if(low[i]>=dfn[cur])
vis[cur]=;//标记当前cur点为割点 }else if(i!=pa)//访问过,但不是父节点,更新low
{
low[cur]=min(low[cur],dfn[i]);
}
}
}
}
int main()
{
while(~scanf("%d",&n)&&n)
{
init();
int temp;
while(~scanf("%d",&temp)&&temp)
{
while(getchar()!='\n')
{
int t;
scanf("%d",&t);
G[temp][t]=G[t][temp]=;
}
}
tarjan(,root);
int cnt=;
for(int i=;i<=n;i++)
if(vis[i])
cnt++;
if(rt_cnt>)
cnt++;
printf("%d\n",cnt);
}
return ;
}
邻接链表实现:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
int mon1[]= {,,,,,,,,,,,,};
int mon2[]= {,,,,,,,,,,,,};
int dir[][]= {{,},{,-},{,},{-,}}; int getval()
{
int ret();
char c;
while((c=getchar())==' '||c=='\n'||c=='\r');
ret=c-'';
while((c=getchar())!=' '&&c!='\n'&&c!='\r')
ret=ret*+c-'';
return ret;
} #define max_v 105
int dfn[max_v];
int low[max_v];
int vis[max_v];
vector<int> vv[max_v];
int depth,n,m,root,rt_cnt; void init()
{
root=;
depth=;
rt_cnt=;
memset(dfn,-,sizeof(dfn));
memset(vis,,sizeof(vis));
memset(low,,sizeof(low));
//for(int i=1;i<=n;i++)
// vv[i].clear();
memset(vv,,sizeof(vv));
} void tarjan(int cur,int pa)
{
dfn[cur]=low[cur]=depth++;
for(int i=;i<vv[cur].size();i++)
{
int temp=vv[cur][i];
if(dfn[temp]==-)
{
tarjan(temp,cur);
low[cur]=min(low[cur],low[temp]); if(cur==root)
rt_cnt++;
else if(low[temp]>=dfn[cur])
vis[cur]=; }else if(temp!=pa)
{
low[cur]=min(low[cur],dfn[temp]);
}
}
} int main()
{
while(~scanf("%d",&n)&&n)
{
init();
int temp;
while(~scanf("%d",&temp)&&temp)
{
while(getchar()!='\n')
{
int t;
scanf("%d",&t);
vv[temp].push_back(t);
vv[t].push_back(temp);
}
}
tarjan(,root);
int cnt=;
for(int i=;i<=n;i++)
if(vis[i])
cnt++;
if(rt_cnt>)
cnt++;
printf("%d\n",cnt);
}
return ;
}

POJ 1144 Network(tarjan 求割点个数)的更多相关文章

  1. [poj 1144]Network[Tarjan求割点]

    题意: 求一个图的割点. 输入略特别: 先输入图中点的总数, 接下来每一行首先给出一个点u, 之后给出一系列与这个点相连的点(个数不定). 行数也不定, 用0作为终止. 这样的输入还是要保证以数字读入 ...

  2. poj 1144 (Tarjan求割点数量)

    题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...

  3. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

  4. POJ 1144 Network (求割点)

    题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...

  5. poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】

    题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...

  6. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  7. UVA 315 315 - Network(求割点个数)

     Network  A Telephone Line Company (TLC) is establishing a new telephone cable network. They are con ...

  8. POJ 3694 Network(Tarjan求割边+LCA)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10969   Accepted: 4096 Descript ...

  9. POJ 1144 Network —— (找割点)

    这是一题找无向图的割点的模板题,割点的概念什么的就不再赘述了.这里讲一下这个模板的一个注意点. dfs中有一个child,它不等于G[u].size()!理由如下: 如上图,1的size是2,但是它的 ...

随机推荐

  1. PeopleSoft 多套Web App Prcs交叉访问

    1.Process服务器比较简单,只需要与数据库关联,系统调用时候就会负载均衡,在PSADMIN增加服务器时候,需要选择在"主菜单>PeopleTools>进程调度器>服务 ...

  2. 多个Portal for ArcGIS 间的协作实操

    原理 协作Colabartion 通过类似握手协议的方式在多个Portal之间建立信任关系.一个协作由一个宿主Portal和多个受邀Portal组成. 工作空间Workspace 一个协作可包含多个工 ...

  3. Flutter 网络请求库http

    http 集成http库 https://pub.dartlang.org/packages/http 添加依赖 dependencies: http: ^ 安装 flutter packages g ...

  4. 你用过这种奇葩的C#注释吗

    博客园一位微软MVP的文章 http://www.cnblogs.com/asxinyu/p/4383402.html#autoid-0-0-0 摘录: 我这里说的奇葩,并不是脱离三种方式,而是其注释 ...

  5. ubuntu 搭建samba共享方案

    1.samba服务安装搭建 sudo apt-get install samba sudo vim /etc/samba/smb.conf workgroup = szsoft 设置用户密码登陆方式s ...

  6. COCOMOII

    一.COCOMOII是什么 cocomo是 COnstructive COst MOdel(建设性成本估算模型)的缩写.最早是由Dr. Barry Boehm在1981年提出.是一种精确的.易于使用的 ...

  7. 使用Eclipse Debug的一些说明

    目录 Debug视图 线程堆栈视图 变量视图 断点视图 表达式视图 代码视图 远程Debug 异常断点 条件断点 表达式 Debug定位第三方插件的问题 Debug一些经验   Debug视图 认识d ...

  8. MySQL应用架构优化-实时数据处理

    1.1. 场景 在和开发人员做优化的时候,讨论最多的应该是结合应用场景编写出合适的SQL.并培训开发应该如何编写SQL让MySQL的性能尽量好.但是有一些的场景对于SQL的优化是行不通的. 打个比方, ...

  9. MySQL5.6锁阻塞分析

    日常维护中,经常会碰到线程被阻塞,导致数据库响应非常慢,下面就看看如何获取是哪个线程导致了阻塞的. blog地址:http://blog.csdn.net/hw_libo/article/detail ...

  10. 推荐一个国外C开发的PHP框架--Phalcon,性能相当好

    本人亲自配置测试后.性能相当不错.不过有一点.使用极不符合国人习惯,甚至和大多数主流PHP框架如Zend Framework,Yii,Ci,Thinkphp都不一样. Phalcon 是一个开源的,全 ...