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. 解决myeclipse2017安装后闪退问题

    修改myeclipse的配置文件myeclipse.ini: 1.将-vm下面的路径改成自己的jdk的javaw.exe的路径 2.在文档最后加上两条语句: -Dgenuitec.honorDevMo ...

  2. 【读书笔记】iOS-网络-理解错误源

    考虑一个字节是如何从设备发往运程服务器以及如何从远程服务器将这个字节接收到设备,这个过程只需要几百毫秒时间,不过确要求网络设备都能正常工作才行.设备网络和网络互联的复杂性导致了分层网络的产生.分层网络 ...

  3. mongodb基础环境搭建

    一.准备工具 (1)mongodb(https://www.mongodb.com/dr/fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus- ...

  4. ubuntu16.04安装matlab2016b

    一.matlab2016b版本下载 在ubuntu下安装matlab2016b,需要三个文件,分别是:Matlab+2016b+Linux64+Crack.rar .R2016b_glnxa64_dv ...

  5. OSGI企业应用开发(八)整合Spring和Mybatis框架(一)

    到目前为止,我们已经学习了如何使用Blueprint將Spring框架整合到OSGI应用中,并学习了Blueprint&Gemini Blueprint的一些使用细节.本篇文章开始,我们將My ...

  6. Javascript、Jquery获取浏览器和屏幕各种高度宽度[mark]

    Javascript: IE中:document.body.clientWidth ==> BODY对象宽度document.body.clientHeight ==> BODY对象高度d ...

  7. List常用几种方式

    第一种,匹配俩个集合中相同的值 , , , , , , }; , , , , , , , , }; var C= listA.Intersect(listB); foreach (var item i ...

  8. 解决Python 爬取ssh证书 的报错问题

    Python3 中会要求添加信任证书,但只是进行爬取数据就没必要了,我们可以忽略它 r1 =requests.get("https://www.baidu.com", verify ...

  9. Windows10设置

    按下Win+R键,输入gpedit.msc,打开组策略窗口

  10. 基于 WPF 平台的 ActiveReports Viewer控件

    ActiveReports 报表控件致力于为组织和个人提供最出色的报表解决方案,多年来ActiveReports已经提供了 Windows Forms.Web.Silverlight和Flash平台的 ...