POJ1236 Network of schools "strong connectivity"

Source: Internet
Author: User

Test instructions

N (2<n<100) schools have a one-way network, each school gets a set of software, can be transmitted through a one-way network to the surrounding schools, question 1: At least the initial number of schools need to distribute software, so that all schools in the network will eventually get the software. 2, at least a few transmission lines (edges) need to be added, so that after any software release to a school, after several transfers, all the schools in the network will eventually get the software.

Ideas:

We can first make the Dag map, then we consider the first problem, the minimum number of sets of software can be fully covered, first test instructions has been guaranteed to be connected. Then we can think that if we put all the points that are not in the edge of the software, it will be feasible. There is bound to be a certain edge through some side eventually from the distribution software must have out of the place to obtain software. Then we consider the second question: This is a connected graph, if we have some points not in the point, some points are not out point, then if we find a way to connect the point and some out point, we can guarantee that the end will be a lot of circle connected. The answer is the maximum value of the point without the edge and the point without the edge.

Code:

#include <iostream>#include<cstdio>#include<algorithm>#include<stack>using namespaceStd;stack<int>DL;Const intMAXN =150000;intHEAD[MAXN],TO[MAXN],NXT[MAXN],DFN[MAXN],LOW[MAXN],INS[MAXN],SG[MAXN];intOUD[MAXN],IND[MAXN];intCnt,n,a,tot,tjs;voidAD_EDG (intXinty) {nxt[++TJS] =Head[x]; HEAD[X]=TJs; To[tjs]=y;}voidsread () {cin>>N;  for(inti =1; I <= n;i++)    {         while(1) {cin>>A; if(!a) Break;        AD_EDG (I,a); }    }}voidTarjan (intX//Tarjan Algorithm{dfn[x]= Low[x] = + +CNT; Dl.push (x), ins[x]=1;  for(inti = Head[x];i;i =Nxt[i]) {        if(!Dfn[to[i]])            {Tarjan (to[i]); LOW[X]=min (Low[x],low[to[i]]); }Else if(Ins[to[i]]) low[x]=min (Low[x],dfn[to[i]]); }    if(Low[x] = =Dfn[x]) {Sg[x]= ++tot;  while(Dl.top ()! = x) ins[dl.top ()] =0, Sg[dl.top ()] =Tot,dl.pop (); INS[X]=0, Dl.pop (); }}voidswork () { for(inti =1; I <= n;i++)        if(!Dfn[i]) Tarjan (i);  for(inti =1; I <= n;i++)         for(intj = Head[i];j;j =Nxt[j])if(Sg[i]! =Sg[to[j]]) Oud[sg[i]++,ind[sg[to[j]]]++; intT1 =0, t2 =0;  for(inti =1; I <= tot;i++)    {        if(!ind[i]) t1++; if(!oud[i]) t2++; }    if(Tot = =1) cout<<"1"<<endl<<"0"<<Endl; Elsecout<<t1<<endl<<max (T2,T1) <<Endl;}intMain () {sread ();    Swork (); return 0;}
View Code

POJ1236 Network of schools "strong connectivity"

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.