P2746 [USACO5.3] Campus Network of schools

Source: Internet
Author: User

Title Description

Some schools connect to a computer network. The schools have agreed that each school will distribute software (known as "school acceptance") to some other schools. Note Even if B is in the distribution list of school A, a is not necessarily in the list of B schools.

You have to write a program calculation, according to the Protocol, in order to allow all schools in the network to use the new software, you must accept the minimum number of new software copies of the school (subtask A). Further, we want to make sure that by sending new software to any school, the software is distributed to all schools on the network. In order to complete this task, we may have to expand the receiving school list to join the new members. The calculation requires a minimum of several extensions, so that no matter which school we send new software to, it will reach all the rest of the school (subtask B). An extension is the introduction of a new member in a school's receiving school list.

Input/output format

Input format:

The first line of the input file includes an integer n: the number of schools in the network (2 <= N <= 100). The school is identified with the first N positive integers.

Each row in the next N row represents a Receive school list (distribution list). Line i+1 includes an identifier for school I's receiving school. Each list ends with 0. An empty list is represented by only one 0.

Output format:

Your program should output two lines in the output file.

The first line should include a positive integer: The solution of subtask A.

The second line should include the solution of sub-task B.

Input and Output Sample input example # #:
52 4 3 04 5 0001 0
Sample # # of output:
12
Description

The title translation comes from Nocow.

Usaco Training Section 5.3

#include <cstdio>#include<stack>#include<algorithm>#include<vector>#defineMAXN 10001using namespacestd;intN,M,LOW[MAXN],DFN[MAXN],SCCNO[MAXN],DEP,SCC,inch[MAXN], out[Maxn],inc,outc;stack<int> s;//stack can effectively prevent the original image from being destroyedvector<int>G[MAXN];voidTintu) {dfn[u]=low[u]=++dep;//-- S.push (U);//u queue     for(intI=0; I<g[u].size (); + +i) {        intv=G[u][i]; if(!dfn[v]) T (v), Low[u]=min (Low[u],low[v]);//v Targan and update if not accessed v Low[u]        Else if(!sccno[v]) low[u]=min (Low[u],dfn[v]);//Otherwise, if V is not strongly connected, update}if(low[u]==Dfn[u]) {        ++SCC;//SCC is a strong connected number recorder         while(1){intX=s.top (); S.pop (); SCCNO[X]=SCC;//mark the strong connected serial number that belongs to and out of the team (erase)            if(X==u) Break;/*out of the squad .*/}}}intMain () {inti,j; scanf ("%d",&N);  for(i=1; i<=n;++i) for(SCANF ("%d", &j); J;SCANF ("%d", &j)) G[i].push_back (j);//Magic Input Method     for(i=1; i<=n;++i)if(!Dfn[i]) t (i);  for(i=1; i<=n;++i) for(j=0; J<g[i].size (); + +j) {            intv=G[i][j]; if(Sccno[i]!=sccno[v]) + +inch[sccno[v]],++ out[Sccno[i]];//Strong connected graph after the connection is indented, update in degree, out degree        }     for(i=1; i<=scc;++i) inc+=inch[i]==0?1:0, outc+= out[i]==0?1:0;//If the entry is 0, add Inc, if the degree is 0, add OUTC    if(scc==1) puts ("1\n0");//in special cases, there is only one strong connected graph, which is itself a strong connected graph.    Elseprintf"%d\n%d\n", Inc,max (INC,OUTC));return 0;//Otherwise, the normal output}

Program was just above,the program was the best language

P2746 [USACO5.3] Campus 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.