POJ 1144 Network "non-direction graph for cutting top template problem"

Source: Internet
Author: User

Description

A telephone line company (TLC) is establishing a new telephone cable network. They is connecting several places numbered by integers from 1 toN. 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's possible to reach through lines every other place, however it need isn't be a direct connection, it CA n go through several exchanges. 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 placesN < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which t Here are a direct line from the this place. These at the veryN lines completely describe the network, i.e., each direct connection of both places in the network I s contained at 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

1A of the white template used

#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include < algorithm>using namespace std; #define MAXN 200int pre[maxn],iscut[maxn],dfs_clock,low[maxn];vector<int>g[    Maxn];int dfs (int u,int fa) {int lowu=pre[u]=++dfs_clock;    int child=0;        for (int i=0;i<g[u].size (); i++) {int v=g[u][i];            if (!pre[v]) {child++;            int Lowv=dfs (V,U);            Lowu=min (LOWU,LOWV);        if (Lowv>=pre[u]) iscut[u]=true;    } else if (PRE[V]&LT;PRE[U]&AMP;&AMP;V!=FA) lowu=min (Lowu,pre[v]);    } if (fa<0&&child==1) iscut[u]=0;    Low[u]=lowu; return LOWU;}    int main () {//Freopen ("Cin.txt", "R", stdin);    int n;        while (~SCANF ("%d", &n) &&n) {char str[200];        memset (pre,0,sizeof (pre));        memset (iscut,0,sizeof (iscut));        for (int i=1;i<=n;i++) g[i].clear ();        dfs_clock=0;        GetChar (); while (Gets (STR) {if (str[0]== ' 0 ') break;            int I,u=0,len=strlen (str);            printf ("len=%d\n", Len);                for (i=0;i<len;i++) {if (str[i]== ") break;                u+= (str[i]-' 0 ');            u*=10;            } i++;           u/=10;            printf ("u=%d\n", u);            int tmp=0;                   for (; i<len;i++) {if (str[i]== ') {tmp/=10;                    printf ("tmp=%d\n", TMP);                    G[u].push_back (TMP);                    G[tmp].push_back (U);                    Tmp=0;                i++;                } tmp+= (str[i]-' 0 ');                tmp*=10;                    if (i==len-1) {tmp/=10;                    printf ("tmp=%d\n", TMP);                    G[u].push_back (TMP);                    G[tmp].push_back (U);                Break       }            }        } for (int i=1;i<=n;i++) {if (!pre[i]) DFS (I,-1); if (!        G[i].empty ()) for (int j=0;j<g[i].size (); j + +) printf ("i=%d,j=%d\n", I,g[i][j]);        } int num=0;        for (int i=1;i<=n;i++) if (iscut[i]) num++;    printf ("%d\n", num); } return 0;}


POJ 1144 Network "non-direction graph for cutting top template problem"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.