UVA 318 Network (no-map-cut points)

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 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.

Cut points:

Template title:

#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string > #include <iostream> #include <queue> #include <cmath> #include <map> #include <stack>  #include <bitset>using namespace std; #define REPF (I, A, b) for (int i = A; I <= B; + + i) #define REP (i, n ) for (int i = 0; i < n; + + i) #define CLEAR (A, X) memset (A, x, sizeof a) typedef long long Ll;typedef pair&    lt;int,int>pil;const int maxn=110;const int maxm=110*110;struct node{int to,next; BOOL col;//for bridge}e[maxm];int head[maxn],cnt;int Dfn[maxn],low[maxn];int s[maxn],instack[maxn];int idex,top,bridge;int    col[maxn],add[maxn];//is cut, the link is added after the deletion point int n;void init () {cnt=top=idex=bridge=0;    CLEAR (head,-1);    CLEAR (dfn,0);    CLEAR (low,0);    CLEAR (instack,0);    CLEAR (col,0); CLEAR (add,0);}    void Addedge (int u,int v) {E[cnt].to=v;e[cnt].next=head[u]; e[cnt].col=false;head[u]=cnt++;} void Tarjan (int u,int pre) {Low[u]=dfn[u]=++idex;    Instack[u]=1;    int son=0;        for (int i=head[u];i!=-1;i=e[i].next) {int v=e[i].to; if (!            Dfn[v]) {son++;            Tarjan (V,u);            if (Low[u]>low[v]) low[u]=low[v];                if (Low[v]>dfn[u])//bridge {bridge++;                E[i].col=true;            E[i^1].col=true;                } if (U!=pre&&low[v]>=dfn[u])//Cut point judge 1 {col[u]=1;            add[u]++;    }} else if (Low[u]>dfn[v]) low[u]=dfn[v];    } if (u==pre&&son>1) col[u]=1;//cut Point Judge 2 if (U==pre) add[u]=son-1;    instack[u]=0; top--;}    int main () {int u,v;        while (~SCANF ("%d", &n) &&n) {init (); while (~SCANF ("%d", &u) &&u) {while (GetChar ()! = ' \ n ') {scanf ("%d", &A                MP;V);                Addedge (U,V);            Addedge (V,u); }} REPF (i,1, n) if (!        Dfn[i]) Tarjan (i,i);        int ans=0;        REPF (I,1,n) if (col[i]) ans++;    printf ("%d\n", ans); } return 0;}


UVA 318 Network (no-map-cut points)

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.