Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 11433 |
|
Accepted: 4551 |
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
52 4 3 04 5 0001 0
Sample Output
12
Source
IOI 1996 Test Instructions: Given the network between schools, the network is one-way. After a school gets the news, the school he points to also gets news. Ask at least how many messages you have to give to get all the school news. Second, ask for at least a few sides, in order to make at any point to release a message, all schools can get. Idea: Tarjan practiced hand problem, the first question, after the connecting block after the contraction point, and then the number of points in degrees 0. Second place, Max (number of degrees 0, out of 0); Note: If there is only one connected block, the second question is output 0
1 /*2 * Author:joshua3 * Created time:2014 September 29 Monday 10:32 59 seconds4 * File Name:poj1236.cpp5 */6#include <cstdio>7 #defineMAXN 1018 #defineMAXM 100019 intN,top,tot,c,num;Ten intHEAD[MAXN],COLOR[MAXN],RD[MAXN],CD[MAXN],S[MAXN],DFN[MAXN],LOW[MAXN]; One BOOLMARK[MAXN]; A structnode - { - intD,next; the } E[MAXM]; - - voidInit () - { + intx, y; -num=c=tot=top=0; + for(intI=1; i<=n;++i) A { atscanf"%d",&y); - while(y) - { -E[++tot].d=y; -e[tot].next=Head[i]; -head[i]=tot; inscanf"%d",&y); - } to } + } - the voidTarjan (intx) * { $ inty;Panax Notoginsengdfn[x]=low[x]=++num; -s[++top]=x; themark[x]=true; + for(intI=head[x];i;i=e[i].next) A { they=e[i].d; + if(!Dfn[y]) - { $ Tarjan (y); $ if(low[y]<Low[x]) -low[x]=Low[y]; - } the Else if(Mark[y] && low[x]>Low[y]) -low[x]=Low[y];Wuyi } the if(low[x]==Dfn[x]) - { Wu++C; - Do About { $y=s[top--]; -color[y]=C; -mark[y]=false; - } A while(y!=x); + } the } - $ voidSolve () the { the intX,y,csum,rsum,ans; the for(intI=1; i<=n;++i) the if(!Dfn[i]) - Tarjan (i); in if(c==1) the { theprintf"1\n0\n"); About return; the } the for(intI=1; i<=n;++i) the for(intj=head[i];j;j=e[j].next) + { -y=e[j].d; the if(color[y]!=Color[i])Bayi { therd[color[y]]++; thecd[color[i]]++; - } - } thecsum=rsum=0; the for(intI=1; i<=c;++i) the { the if(!rd[i]) + +rsum; - if(!cd[i]) + +csum; the } the if(rsum>csum) ans=rsum; the Elseans=csum;94printf"%d\n", rsum); theprintf"%d\n", ans); the } the 98 intMain () About { - while(SCANF ("%d", &n) >0)101 {102 init ();103 solve ();104 } the return 0;106}
poj1236 Network of schools