Cogs--c 908. Campus Network | | Rokua--p 2746 [USACO5.3] Campus Network of schools

Source: Internet
Author: User

http://www.cogs.pro/cogs/problem/problem.php?pid=908 | | https://www.luogu.org/problem/show?pid=2746

★ Import File: schlnet.in output file: schlnet.out Simple comparison
Time limit: 1 s memory limit: MB

Usaco/schlnet (translated by Felicia Crazy)

Describe

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 If B is in the distribution list of school A, then a does not have to be 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.

Program Name:schlnetinput FORMAT (file schlnet.in)

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 (file schlnet.out)

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.

SAMPLE INPUT (file schlnet.in)

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

SAMPLE OUTPUT (file schlnet.out)
1

2

A: The point after which the indentation is zero, and B: The point after which the degree of the indentation is zero and (the number of points after the indent point-the count of the point that is zero in) takes Max

When there's only one connecting block.

1#include <algorithm>2#include <cstdio>3 4 using namespacestd;5 6 Const intN the* the);7 intn,ans_a,ans_b,cnt;8 9 intHead[n],sumedge;Ten structEdge One { A     intV,next; -Edge (intv=0,intnext=0): V (v), next (next) {} - }edge[n]; the voidInsintUintv) - { -edge[++sumedge]=Edge (V,head[u]); -head[u]=Sumedge; + } -  + intTim,dfn[n],low[n]; A intTop,stack[n],instack[n]; at intSumcol,col[n],rd[n],cd[n],point[n]; - voidDFS (intNow ) - { -dfn[now]=low[now]=++Tim; -Stack[++top]=now; instack[now]=1; -      for(intI=head[now];i;i=edge[i].next) in     { -         intv=edge[i].v; to         if(!dfn[v]) DFS (v), low[now]=min (low[now],low[v]); +         Else if(Instack[v]) low[now]=min (low[now],dfn[v]); -     } the     if(low[now]==Dfn[now]) *     { $col[now]=++Sumcol;Panax Notoginsengpoint[sumcol]++; -          for(; stack[top]!=now;top--) the         { +col[stack[top]]=Sumcol; Apoint[sumcol]++; theinstack[stack[top]]=0; +         } -instack[now]=0; top--; $     } $ } -  - intMain () the { - //freopen ("schlnet.in", "R", stdin);Wuyi //freopen ("Schlnet.out", "w", stdout); thescanf"%d",&n); -      for(intu=1; u<=n;u++) Wu          for(intV;SCANF ("%d", &v) &&v;) ins (u,v); -      for(intI=1; i<=n;i++) About         if(!Dfn[i]) DFS (i); $      for(intu=1; u<=n;u++) -     { -          for(intI=head[u];i;i=edge[i].next) -         { A             intv=edge[i].v; +             if(Col[u]==col[v])Continue; the             if(!rd[col[v]]) cnt++; -cd[col[u]]++; rd[col[v]]++; $         } the     }     the      for(intI=1; i<=sumcol;i++) the     { the         if(!rd[i]) ans_a++; -         if(!cd[i]) ans_b++; in} Ans_b=max (ans_b,sumcol-CNT); the     if(sumcol==1) ans_b=0; theprintf"%d\n%d", ans_a,ans_b); About     return 0; the}

Cogs--c 908. Campus Network | | Rokua--p 2746 [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.