Network
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 10907   Accepted: 5042

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

模板~

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int MAXN = ;
const int MAXM = ;
struct Edge
{
int to,next;
bool cut;
} edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
bool Instack[MAXN],cut[MAXN];
int bridge,add_block[MAXN]; void addedge(int u,int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
}
void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for(int i = head[u]; i != -; i = edge[i].next)
{
v = edge[i].to;
if(v == pre)
continue;
if( !DFN[v] )
{
son++;
Tarjan(v,u);
if(Low[u] > Low[v]) Low[u] = Low[v]; if(Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i^].cut = true;
} if(u != pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if(Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if(u == pre && son > ) cut[u] = true;
if(u == pre) add_block[u] = son -;
Instack[u] = false;
top--;
}
void solve(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = bridge = ;
for(int i = ; i <= N; i++)
if( !DFN[i])
Tarjan(i,i);
int ans = ;
for(int i = ; i <= N; i++)
if(cut[i])
ans++;
printf("%d\n",ans);
}
void init()
{
tot = ;
memset(head,-,sizeof(head));
}
int main(void)
{
int n;
int maze[][];
while(scanf("%d",&n),n)
{
char ss[];
init();
memset(maze,,sizeof(maze));
getchar();
while(cin.getline(ss,),ss[] != '')
{
int u = ,cur = ,l = (int)strlen(ss);
while(ss[cur] != ' ' && cur < l)
{
u*= ;
u += ss[cur] - '';
cur++;
}
int v;
while(ss[cur] && cur < l)
{
v = ;
while(ss[cur] != ' ' && cur < l)
{
v*= ;
v += ss[cur] - '';
cur++;
}
maze[u][v] = maze[v][u] = ;
cur++;
}
}
for(int i = ; i <= n; i++)
for(int j = ; j < i; j++)
if(maze[i][j])
{
addedge(i,j);
addedge(j,i);
}
solve(n);
}
return ;
}

最新文章

  1. 如何从零基础学习VR
  2. python 调用浏览器方法
  3. Redis的一些坑
  4. 【翻译十三】java-并发之饥饿与活锁
  5. 利用ngxtop实时监控nginx的访问情况
  6. XDocument 获取包括第一行的声明(版本、编码)的所有节点
  7. QA:java.lang.RuntimeException:java.io.FileNotFoundException:Resource nexus-maven-repository-index.properties does not exist.
  8. I Hate It(线段数组基础题)
  9. 【LeetCode】14. Longest Common Prefix 最长前缀子串
  10. centos7启动时出现“无法应用原保存的显示器配置”
  11. 百度——LBS.云 v2.0——云存储的POI创建和删除--Android 源码
  12. 基于Spring提供支持不同设备的页面
  13. CSS3属性之圆角效果——border-radius属性
  14. 22_Android中的本地音乐播放器和网络音乐播放器的编写,本地视频播放器和网络视频播放器,照相机案例,偷拍案例实现
  15. 折腾Java设计模式之观察者模式
  16. hibernate一级缓存及对象的状态
  17. P1396 营救(并查集+二分)
  18. 转:在Struts 2中实现文件上传
  19. 第十节 JS运动中级
  20. python2.7中MySQLdb的安装与使用详解

热门文章

  1. mysql主从跳过错误
  2. js封装设置获取cookie
  3. linux mint &amp; ubuntu 安装QQ国际版
  4. 由VMnet引起的browser-sync故障解决方案
  5. 从xmlns的作用说起
  6. Spring MVC(五)--控制器通过注解@RequestParam接受参数
  7. flink第一个应用
  8. Hadoop构架概览
  9. Luogu P1401 城市(二分+网络流)
  10. 跟我一起在ubuntu中安装docker