Jdoj-1833:network of Schools Campus Network

Source: Internet
Author: User

1833:network of Schools Campus Network time limit:1 Sec Memory limit:128 MB
submit:155 solved:63
[Submit] [Status] [Web Board] 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 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.

Input

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

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 Input4 3 5 0001 0Sample Output ASource

Usaco

Summary: Tarjan + pinch point
#include <bits/stdc++.h>using namespacestd;Const intMAXN =100005;intDFN[MAXN], LOW[MAXN], n, tot =0, Tim;BOOLVIS[MAXN]; stack<int> s;intC[MAXN], R[MAXN];intHEAD[MAXN], cnt =1, num, COLOR[MAXN];structnode{intV, NXT;} G[MAXN];voidInsertintUintv) {g[cnt]= (Node) {V, head[u]}; Head[u] = cnt++;}voidTarjan (intx) {vis[x]=true;    S.push (x); LOW[X]= Dfn[x] = + +Tim;  for(inti = head[x]; I i =g[i].nxt) {        intv =g[i].v; if(!Dfn[v])            {Tarjan (v); LOW[X]=min (low[x], low[v]); } Else if(Vis[v]) low[x] =min (low[x], dfn[v]); } if(Dfn[x] = =Low[x]) {Tot++;  while(1) {            intnow =S.top (); S.pop (); Vis[now]=false; Color[now]=tot; if(now = = x) Break; }    }}intMain () {scanf ("%d", &N);  for(inti =1; I <= N; ++i) { for(; ;) {            intA scanf"%d", &a); if(A = =0) Break; Insert (I, a); }    }     for(inti =1; I <= N; ++i)if(!Dfn[i]) Tarjan (i); intANS1 =0, Ans2 =0;  for(intU =1; U <= N; ++u) { for(inti = Head[u]; I i =g[i].nxt) {            intv =g[i].v; if(Color[u]! =Color[v]) {C[color[u]]++; R[COLOR[V]]++; }        }    }     for(inti =1; I <= tot; ++i) {if(!c[i]) ans1++; if(!r[i]) ans2++; } printf ("%d\n", ANS2); if(Tot = =1) printf ("0\n"); Elseprintf"%d\n", Max (ans1, ans2)); return 0;}

Jdoj-1833:network of Schools Campus Network

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.