Rokua P2746 [USACO5.3] Campus Network of schools

Source: Internet
Author: User

P2746 [USACO5.3] Campus Network of schools topic 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 sample #: Copy
52 4 3 04 5 0001 0
Output Example # #: Replication
12
Description

The title translation comes from Nocow.

Usaco Training Section 5.3

/*According to test instructions this is a connected graph, so do not have to build two-way edge BFS to find the Unicom block and the simple point is: A. The number of points that are zero after the indent point, B. The number of points that have zero max{after the indentation, and the number of points with zero degrees}*/#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#defineMAXN 101using namespacestd;intN,NUM,HEAD[MAXN],NUM2,HEAD2[MAXN];intDFN[MAXN],LOW[MAXN],G_NUM,CNT,ST[MAXN],TOP,BELONG[MAXN];intRU[MAXN],CHU[MAXN];BOOLVIS[MAXN],CON[MAXN][MAXN];structnode{int  from, To,pre;} E[MAXN*MAXN];voidInsert (int  from,intTo ) {e[++num].to=to ; E[num]. from= from; E[num].pre=head[ from]; head[ from]=num;}voidTarjan (intu) {CNT+ +;d fn[u]=low[u]=cnt;st[++top]=u;vis[u]=1;  for(intI=head[u];i;i=e[i].pre) {        intv=e[i].to; if(!Dfn[v])            {Tarjan (v); Low[u]=min (low[u],low[v]); }        Else {            if(Vis[v]) low[u]=min (low[u],dfn[v]); }    }    if(dfn[u]==Low[u]) {G_num++;  while(st[top]!=T) {            intx=st[top];top--; VIS[X]=0; BELONG[X]=G_num; }        intx=st[top];top--; VIS[X]=0; BELONG[X]=G_num; }}intMain () {scanf ("%d",&N); intx;  for(intI=1; i<=n;i++)         while(1) {scanf ("%d",&x); if(x==0) Break;        Insert (I,X); }     for(intI=1; i<=n;i++)        if(!Dfn[i])    Tarjan (i);  for(intI=1; i<=num;i++){        if(Belong[e[i]. from]!=Belong[e[i].to]) {Ru[belong[e[i].to]]++; Chu[belong[e[i]. from]]++; }    }    intcnt1=0, cnt2=0;  for(intI=1; i<=g_num;i++){        if(ru[i]==0) cnt1++; if(chu[i]==0) cnt2++; }    if(g_num==1) printf ("1\n0"); Elseprintf"%d\n%d", Cnt1,max (Cnt1,cnt2));}

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