Network
Description
A telephone line company (TLC) is establishing a new telephone cable network. They is connecting several places numbered by integers from 1 to N. No. Places has the same number. The lines is bidirectional and always connect together both 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 is a direct connection, it can go through several E Xchanges. From time to time the power supply fails in a place and then the exchange does not operate. The officials from TLC realized so in such a case it can happen that besides the fact that the place with the failure is Unreachable, this can also cause the some other places cannot connect to each of the other. In such a case we'll say the place (where the failure
occured) is critical. Now the officials is 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. 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 are a Direct line from this place. These at the very N lines completely describe the network, i.e., each direct connection of both places in the network is Contai Ned at the least in one row. All numbers on one line is separated
by one space. Each block ends with a line containing just 0. The last block had 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
55 1 2 3 4062 1 35 4 6 200
Sample Output
12
Hint
You need to determine the end of one line. In order to make it's easy to Determine,there is no extra blank before the end of each line. Idea: is to seek cut point nothing to say; be careful.
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineMoD 1000000007#defineINF 999999999intScan () {intres =0, ch; while( ! (ch = getchar ()) >='0'&& CH <='9' ) ) { if(ch = = EOF)return 1<< - ; } Res= CH-'0' ; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;}intdfn[1010];intlow[1010];inthead[1010];intans[1010];intvisit[1010];intIndex,root,son,node,jiedge;struct is{ intu,v; intNext;} edge[1010];voidAddintXinty) {Jiedge++; EDGE[JIEDGE].U=x; EDGE[JIEDGE].V=y; Edge[jiedge].next=Head[x]; HEAD[X]=Jiedge; Jiedge++; EDGE[JIEDGE].U=y; EDGE[JIEDGE].V=x; Edge[jiedge].next=Head[y]; Head[y]=Jiedge;}voidDfsintu) { for(intI=head[u];i;i=Edge[i].next) { intv=edge[i].v; if(visit[v]==0) {Visit[v]=1;++index; DFN[V]=low[v]=index; DFS (v); Low[u]=min (low[u],low[v]); if(low[v]>=Dfn[u]) { if(u==root) son++; ElseAns[u]++; } } ElseLow[u]=min (low[u],dfn[v]); }}voidTrajan () {memset (visit,0,sizeof(visit)); memset (ans,0,sizeof(ans)); Index=1; Root=1; Son=0; low[1]=dfn[1]=1; visit[1]=1; DFS (1);}intMain () {intu,v; intflag=0; while(SCANF ("%d", &node)! =EOF) {memset (head,0,sizeof(head)); Jiedge=0; if(node==0) Break; while(1) { intu,v; scanf ("%d",&T); if(!u) Break; while(GetChar ()! ='\ n') {scanf ("%d",&v); Add (U,V); }} Trajan (); intAnswer=0; if(son>1) Answer++; for(intI=2; i<=node;i++) if(Ans[i]) answer++; printf ("%d\n", answer); } return 0;}
View Code
POJ 1144 Network No-map-seeking cutting point