POJ 1236 Network of schools

Source: Internet
Author: User

Network of Schoolstime limit:1000msmemory limit:10000kbthis problem would be judged onPKU. Original id:1236
64-bit integer IO format: %lld Java class name: Main 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.
InputThe 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. OutputYour 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
SourceIOI 1996 Problem Solving: Strong connected shrink points, the number of blocks with a degree of 0, and the number of blocks with a degree of 0.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <climits>7#include <vector>8#include <queue>9#include <cstdlib>Ten#include <string> One#include <Set> A#include <stack> - #defineLL Long Long - #definePII pair<int,int> the #defineINF 0x3f3f3f3f - using namespacestd; - Const intMAXN = the; -vector<int>G[MAXN]; +stack<int>Stk; - intDFN[MAXN],LOW[MAXN],BELONG[MAXN],CNT,SCC; + intNinch[MAXN], out[MAXN]; A BOOLINSTACK[MAXN]; at voidTarjan (intu) { -Dfn[u] = Low[u] = + +CNT; -Instack[u] =true; - stk.push (u); -      for(inti =0; I < g[u].size (); i++){ -         if(!Dfn[g[u][i]]) { in Tarjan (G[u][i]); -Low[u] =min (Low[u],low[g[u][i]]); to}Else if(Dfn[g[u][i]] && Instack[g[u][i]]) low[u] =min (Low[u],dfn[g[u][i]]); +     } -     if(Dfn[u] = =Low[u]) { theScc++; *         intv; $          Do{Panax Notoginsengv =stk.top (); -INSTACK[V] =false; the Stk.pop (); +BELONG[V] =SCC; A} while(V! =u); the     } + } - intMain () { $     inti,j,v; $      while(~SCANF ("%d",&N)) { -          for(i =0; I <= N; i++){ -Dfn[i] = Low[i] = Belong[i] =0; the             inch[I] = out[I] =0; -Instack[i] =false;Wuyi g[i].clear (); the         } -          while(!stk.empty ()) Stk.pop (); WuCNT = SCC =0; -          for(i =1; I <= N; i++) About              while(SCANF ("%d",&V) G[i].push_back (v); $          for(i =1; I <= N; i++)if(!Dfn[i]) Tarjan (i); -          for(i =1; I <= N; i++){ -              for(j =0; J < G[i].size (); J + +){ -                 if(Belong[i]! =Belong[g[i][j]]) { A                     inch[belong[g[i][j]]]++; +                      out[belong[i]]++; the                 } -             } $         } the         intANS1 =0, Ans2 =0; the          for(i =1; I <= SCC; i++){ the             if(!inch[i]) ans1++; the             if(! out[i]) ans2++; -         } inprintf"%d\n%d\n", ANS1,SCC = =1?0: Max (ANS1,ANS2)); the     } the     return 0; About}
View Code

POJ 1236 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.