Network
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 11042 |
|
Accepted: 5100 |
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. Test instructions: A number n next up to n rows (can be less than n rows) per row The first number a next is the number of random n-1 B,a and B connected to the final composition of the total number of cut points my input method really do not know fault the input slightly pits
#include <stdio.h> #include <string.h> #include <stack> #include <algorithm> #define MAX 1100# Define MAXM 2000100#define INF 0x7fffffusing namespace std;struct node{int beg,end,next;} Edge[maxm];int low[max],dfn[max];int head[max],ans;int dfsclock;int iscut[max];void init () {Ans=0;memset (head,-1, sizeof (head));} void Add (int u,int v) {edge[ans].beg=u;edge[ans].end=v;edge[ans].next=head[u];head[u]=ans++;} void Tarjan (int u,int fa) {int v,i;low[u]=dfn[u]=++dfsclock;int son=0;for (i=head[u];i!=-1;i=edge[i].next) {v=edge[i]. End;if (!dfn[v]) {Son++;tarjan (v,u); Low[u]=min (Low[u],low[v]); if (u!=fa&&dfn[u]<=low[v]) iscut[u]=1;} else Low[u]=min (Dfn[v],low[u]);} if (fa==u&&son>1) iscut[u]=1;} void Find (int l,int r) {memset (low,0,sizeof (Low)); Memset (Dfn,0,sizeof (DFN)); Memset (Iscut,0,sizeof (iscut));d Fsclock =0;for (int i=l;i<=r;i++) {if (!dfn[i]) Tarjan (i,i);}} int main () {int n,m,j,i,t;int a,c,len;char B;char s[5010];while (scanf ("%d", &n), n) {init (); int Sum=0;while (scanf ("%d", &a), a) {while (GetChar ()! = ' \ n ') {scanf ("%d", &c); Add (A,C); Add (C,a); }}//while (scanf ("%d", &a), a) I really don't know where this input is wrong always wa//{//while (scanf ("%c", &b) &&b! = ' \ n ')//{//c=b-' 0 ';//add (a,c);//add (c,a);//}//}find (1,n); for (i=1;i<=n;i++) {if (iscut[i]) sum++;} printf ("%d\n", sum);} return 0;}
POJ 1144 Network "Total number of cut points for two connected components"