Roughly test instructions gives you a graph with a point number of n<=100.
Solve two sub-tasks:
1: At least how many points information, the information of these points can be spread along the side of the full map.
2: At least how many edges to add, so that the whole graph strong unicom.
A direction-free graph is obtained after calculating the re-contraction point of the strong unicom component.
The number of points for which the entry is 0 is T1, and the T2 of the number of degrees is 0.
The answer for 1 is the number of points with a T1 of 0 after the strong unicom contraction point.
The answer for 2 is Max (T1,T2).
Note A special case: if there is only one point after the contraction point (that is, the original image is strongly connected) at this time t1=1,t2=1 but the answer to the second task should be 0.
AC Code:
#include <cstdio>#include<cmath>#include<cstring>#include<iostream>#defineRep (i,a,b) for (int i=a;i<=b;++i)using namespacestd;Const intmaxn= the;intn,cnt;intGRAPH[MAXN][MAXN];intDFN[MAXN],LOW[MAXN],STAP[MAXN],LABEL[MAXN];BOOLINSTAKE[MAXN];intstop,bcnt;intADJM[MAXN][MAXN];int inch[MAXN], out[MAXN];voidinit () {memset (graph,0,sizeof(graph)); memset (DFN,0,sizeof(DFN)); memset (inch,0,sizeof(inch)); memset ( out,0,sizeof( out)); memset (ADJM,0,sizeof(ADJM)); memset (Instake,0,sizeof(Instake)); intT; CNT=0; stop=0; Bcnt=0; Rep (I,1, N) { while(SCANF ("%d", &t) = =1&&t) {graph[i][++graph[i][0]]=T; } }}voidTarjan (intu) {Dfn[u]=low[u]=++CNT; Instake[u]=1; stap[++stop]=T; Rep (I,1, graph[u][0]) { intv=Graph[u][i]; if(!Dfn[v]) {Tarjan (v); if(Low[v]<low[u]) low[u]=Low[v]; } Else if(Instake[v]&&dfn[v]<low[u]) low[u]=Dfn[v]; } intJ; if(dfn[u]==Low[u]) { ++bcnt; Do{J=stap[stop--]; INSTAKE[J]=0; LABEL[J]=bcnt; } while(j!=T); }}intMain () {//freopen ("In.txt", "R", stdin); while(SCANF ("%d", &n) = =1) {init (); Rep (I,1, N) { if(!Dfn[i]) Tarjan (i); } if(bcnt==1) {printf ("1\n0\n");Continue; } Rep (I,1, N) {Rep (J,1, graph[i][0]) { intv=Graph[i][j]; if(label[i]!=Label[v]) { out[label[i]]++; inch[label[v]]++; } } } intt1=0, t2=0; Rep (I,1, bcnt) { if(inch[i]==0) t1++; if( out[i]==0) t2++; } printf ("%d\n%d\n", T1,max (T1,T2)); } return 0;}
POJ 1236 Strong Unicom components