"Connected Graph | Strong connected component + Pinch point" POJ-1236 Network of schools

Source: Internet
Author: User

Network of schools
Time limit:1000ms Memory limit:10000k

Description
A number of schools is connected to a computer network. Agreements has been developed among those Schools:each School maintains a list of schools to which it distributes Softwa Re (the "Receiving schools"). Note that if B was in the distribution list of school A, then a does not necessarily appear in the list of school B
You is to write a program this computes the minimal number of schools that must receive a copy of the new software in Ord Er for the software to reach all schools in the network according to the agreement (Subtask A). As a further task, we want to ensure is sending the copy of new software to an arbitrary school, this software would r Each of the schools in the network. To achieve this goal we are having to extend the lists of receivers by new members. Compute the minimal number of extensions that has to is made so this whatever school we send the new software to, it'll Reach all other schools (Subtask B). One extension means introducing one new member into the list of receivers of one school.

Input
The first line contains a integer n:the number of schools in the network (2 <= N <= 100). The schools is identified by the first N positive integers. Each of the next N lines describes a list of receivers. The line i+1 contains the identifiers of the receivers of school I. Each list is ends with a 0. An empty list contains a 0 alone in the line.

Output
Your program should write, lines to the standard output. The first line should contain one positive integer:the solution of subtask A. The second line should contain the solution of subtask B.

Sample Input

5
2 4 3 0
4 5 0
0
0
1 0

Sample Output

1
2

Source
IOI 1996

Test Instructions : Given a forward connected graph, (1) at least from a few points can traverse the entire map, (2) Add at least a few edges can make the graph into a strong connected graph.
idea : The first question is simple, the number of points after which the indentation is 0 after the strong connected component shrinks.
Second, there are a number of points after the indentation of 0 and a degree of 0, the points are connected to each other, it will constitute a strong connected graph. So the answer is the number of points with a max{of 0, and the number of points with a degree of 0}.
P.S. Note that there is only one point left after the indentation, the number of points at which the degree is 0 and the out of 0 is 1, but there is no need to add edges.

/* * ID:J.SURE.1 * PROG: * lang:c++ * *#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <ctime>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <climits>#include <iostream>#define PB push_back#define LL Long Longusing namespace STD;Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-8;/****************************************/Const intN = the, M = N*n;structEdge {intV, next; Edge () {} Edge (int_v,int_next): V (_v), Next (_next) {}}e[m];intDfn[n], Head[n], scc_id[n];intTot, deep, scc_cnt, N;intline[m][2], In[n], out[n]; Stack <int>SvoidInit () {memset(Head,-1,sizeof(head));memset(DFN,0,sizeof(DFN));memset(In,0,sizeof(in));memset(Out,0,sizeof(out)); tot = deep = scc_cnt =0;}voidAddintUintV) {E[tot] = Edge (V, Head[u]); Head[u] = tot++;}intDfsintu) {intLowu = Dfn[u] = ++deep; S.push (U); for(inti = Head[u]; ~i; i = e[i].next) {intv = e[i].v;if(!dfn[v]) {intLOWV = DFS (v);        Lowu = min (Lowu, LOWV); }Else if(!scc_id[v])        {Lowu = min (Lowu, dfn[v]); }    }if(Lowu = = Dfn[u]) {scc_cnt++;//printf ("scc_cnt is%d\n", scc_cnt);         while(1) {intx = S.top ();            S.pop (); SCC_ID[X] = scc_cnt;//number from 1            if(x = = u) Break; }    }returnLowu;}voidTarjan () { for(inti =1; I <= N; i++) {if(!dfn[i]) DFS (i); }}intMain () {#ifdef j_sureFreopen ("000.in","R", stdin);//freopen ("999.out", "w", stdout);#endif    scanf("%d", &n); Init ();intJ, L =0; for(inti =1; I <= N; i++) { while(scanf("%d", &j), j) {Add (I, j); line[l][0] = i; line[l][1] = J;        l++; }} Tarjan ();if(scc_cnt = =1) {printf("1\n0\n");return 0; } for(inti =0; i < L; i++) {intU = scc_id[line[i][0]], V = scc_id[line[i][1]];if(U! = V)            {in[v]++;        out[u]++; }    }intNoin =0, Noout =0; for(inti =1; I <= scc_cnt; i++) {if(!in[i]) noin++;if(!out[i]) noout++; }printf("%d\n", Noin);printf("%d\n", Max (Noin, noout));return 0;}

"Connected Graph | Strong connected component + Pinch point" POJ-1236 Network of schools

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.