Poj1144--d-network (connecting component, cutting point)

Source: Internet
Author: User

D- NetworkTime limit:MS Memory Limit:10000KB 64bit IO Form At:%i64d &%i64u Submit Status

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.

Give n points, and a little U-connected edge, solve how many cut points

Note that for the root, only a subtree larger than one is a cut point.

#include <cstdio> #include <cstring> #include <algorithm> #include <stack>using namespace std;#    Define MAXN 120struct node{int u, v; int next;} Edge[1000000];int HEAD[MAXN], CNT, vis[1000000]; int DNF[MAXN], LOW[MAXN], time, ans, flag[maxn], num; stack <in    t> sta;void Add (int u,int v) {edge[cnt].u = u;    EDGE[CNT].V = v;    Edge[cnt].next = Head[u];    Head[u] = cnt++;    edge[cnt].u = v;    EDGE[CNT].V = u;    Edge[cnt].next = Head[v]; HEAD[V] = cnt++;}    void Tarjan (int u) {dnf[u] = low[u] = ++time;    int V, I, J;        for (i = head[u]; i =-1; i = edge[i].next) {if (vis[i]) continue;        if (U = = 1) num++;        Vis[i] = vis[i^1] = 1;        v = edge[i].v;            if (!dnf[v]) {Sta.push (i);            Tarjan (v);            Low[u] = min (low[u],low[v]);                if (Low[v] >= dnf[u] &&!flag[u]) {ans++; Flag[u] = 1;            }} else if (Dnf[v] < Dnf[u]) {Sta.push (v);        Low[u] = min (low[u],dnf[v]);    }}}int Main () {int n, m, U, v;    Char ch;        while (scanf ("%d", &n) && N) {memset (head,-1,sizeof (head));        memset (vis,0,sizeof (VIS));        memset (dnf,0,sizeof (DNF));        memset (low,0,sizeof (Low));        memset (flag,0,sizeof (flag));        CNT = time = ans = num = 0;                while (scanf ("%d", &u) && u) {while (scanf ("%d%c", &v, &ch)) {                Add (U,V);            if (ch = = ' \ n ') break;        }} while (!sta.empty ()) Sta.pop ();        Tarjan (1);        if (num = = 1) ans--;    printf ("%d\n", ans); } return 0;}


Poj1144--d-network (connecting component, cutting point)

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.