poj1144-Network(求割点)
NetworkTime Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7278 | Accepted: 3419 |
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.
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;
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
简单的求割点的算法,直接套模板就好
- #include<stdio.h>
- #include<string.h>
- struct node
- {
- int to;
- int next;
- } p[10005];
- int dfn[105],low[105];
- int head[105],vis[105];
- int cut[105];
- int m,e,root;
- int min(int a,int b)
- {
- return a<b?a:b;
- }
- void add(int u,int v)
- {
- p[e].to=v;
- p[e].next=head[u];
- head[u]=e++;
- }
- void dfs(int u,int father,int a)
- {
- int son=0;
- vis[u]=1;
- dfn[u]=low[u]=a;
- for(int i=head[u]; i!=-1; i=p[i].next)
- {
- int v=p[i].to;
- if(vis[v]==1&&v!=father)
- low[u]=min(low[u],dfn[v]);
- if(vis[v]==0)
- {
- dfs(v,u,a+1);
- son++;
- low[u]=min(low[u],low[v]);
- if((u==root&&son>1)||(u!=root&&dfn[u]<=low[v]))
- cut[u]=1;
- }
- }
- vis[u]=2;
- }
- int main()
- {
- while(scanf("%d",&m)&&m!=0)
- {
- memset(dfn,0,sizeof(dfn));
- memset(low,0,sizeof(low));
- memset(head,-1,sizeof(head));
- memset(vis,0,sizeof(vis));
- memset(cut,0,sizeof(cut));
- int n;
- e=0;
- while(scanf("%d",&n)&&n!=0)
- {
- while(getchar()!='\n')
- {
- int a;
- scanf("%d",&a);
- add(n,a);
- add(a,n);
- }
- }
- root=1;
- int sum=0;
- dfs(1,-1,1);
- for(int i=1; i<=m; i++)
-  
补充:软件开发 , C++ ,
上一个:在C++中实现事件(委托)
下一个:远程注入执行函数
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊