POJ1144-Network(割顶模板题)
2014-07-22 09:45
274 查看
Network
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
Sample Output
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
Central Europe 1996
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9134 | Accepted: 4292 |
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
Central Europe 1996
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; const int MAXN=105;//500; const int MAXM=5050;//0500; int first[MAXN],low[MAXN],dfn[MAXN],inq[MAXN],cut[MAXN]; int next[MAXM],u[MAXM],v[MAXM]; int cnt,scnt,rt,rt_son; int MIN(int a,int b){ return a>b?b:a;} void dfs(int cur) { int e; dfn[cur]=low[cur]=++scnt; inq[cur]=1; for(e=first[cur];e!=-1;e=next[e]) if(!inq[v[e]])//white { dfs(v[e]); if(cur==rt)rt_son++; else { low[cur]=MIN(low[cur],low[v[e]]); if(low[v[e]]>=dfn[cur])cut[cur]=1; } } else if(dfn[v[e]]<low[cur]) low[cur]=dfn[v[e]]; } void add_ded(int a,int b) { u[cnt]=a; v[cnt]=b; next[cnt]=first[a]; first[a]=cnt++; } int main() { //freopen("123.txt","r",stdin); int n,m,i,s,t; while(~scanf("%d",&n),n) { cnt=0;scnt=0; memset(first,-1,sizeof first); memset(next,-1,sizeof next); while(scanf("%d",&s),s) { while(getchar()!='\n') { scanf("%d",&t); add_ded(s,t); add_ded(t,s); } } rt=1;rt_son=0; memset(inq,0,sizeof inq); memset(cut,0,sizeof cut); dfs(1); if(rt_son>1)cut[rt]=1; int sum=0; for(i=1;i<=n;i++) sum+=cut[i]; printf("%d\n",sum); } return 0; }
相关文章推荐
- poj 1144 Network 图的割顶判断模板
- poj 1144 Network 图的割顶判断模板
- poj1144 Network(割顶)
- poj 1144 Network【无向图求割顶模板题】
- poj1144(求割顶模板题)
- POJ 1144 Network(无向图的割顶和桥模板题)
- POJ1144-NetWork(无向图的割顶)
- 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)
- POJ 1144 Network (割点模板题)
- UVA 315 - Network (求割点数模板题)
- UVA315-Network(求割点个数,模板题)||tarjan
- POJ 1144 Network (割顶)
- poj 1144 Network(模板题)(Tarjan 关节点的朴素算法)
- 求割点模板——Network
- POJ 1459 Power Network 网络流模板题
- POJ 3164 Command Network 最小树形图模板
- POJ 3164 Command Network(最小树形图模板)
- POJ 3164 Command Network (最小树形图模板 朱刘算法)
- 洛谷3388 【模板】割点(割顶)
- 图论模板 求割顶/判断二分图