Title Address: HDU 2767
Test instructions: Give a map with a direction to make the graph strong and connect at least a few edges.
Idea: First of all, the strong connected component of this graph, if 1, then the output 0 (prove that the graph does not need to add edge is already strong connectivity), otherwise the indentation point. Traverse all the edges of the original, if the 2 points in the different strong connected components, build the edge, constitute a new picture. Statistics the degree and the degree of the midpoint of the new graph, the take-in degree is equal to 0 and the out degree equals 0 the maximum value (because after the strong connected indent point, the whole picture becomes a non-loop of the direction graph, to make it strong connectivity, only need to be =0 and out of the degree of =0 points to add the edge, to ensure that the addition of the edge and no degree of 0 points, So take both of the maximum values)
*#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;Const intmaxn=21010;intHEAD[MAXN],DFN[MAXN],LOW[MAXN],BELONG[MAXN],STAK[MAXN],INSTACK[MAXN];intIN[MAXN],OUT[MAXN];intincnt,outcnt;intCnt,index,top,ans;structNode {intU, V, next;} edge[maxn*3];voidAddintUintV) {edge[cnt].v=v; Edge[cnt].next=head[u]; head[u]=cnt++;}voidInit () {memset(head,-1,sizeof(head));memset(DFN,0,sizeof(DFN));memset(Instack,0,sizeof(Instack)); cnt=index=top=ans=0;memset(In,0,sizeof(in));memset(Out,0,sizeof(out)); Incnt=outcnt=0;}voidTarjan (intu) {dfn[u]=low[u]=++index; Stak[++top]=u; instack[u]=1; for(intI=head[u]; i!=-1; I=edge[i].next) {intV=EDGE[I].V;if(!dfn[v]) {Tarjan (v); Low[u]=min (Low[u],low[v]); }Else if(Instack[v]) low[u]=min (Low[u],dfn[v]); }if(Dfn[u]==low[u]) {ans++; while(1) {intv=stak[top--]; instack[v]=0; Belong[v]=ans;if(U==V) Break; } }}intMain () {intT, N, M,i, J;intU,v;scanf("%d", &t); while(t--) {scanf("%d%d", &n,&m); Init (); while(m--) {scanf("%d%d", &u,&v); Add (U,V); } for(i=1; i<=n; i++) {if(!dfn[i]) Tarjan (i); }if(ans==1) {printf("0\n");Continue; } for(i=1; i<=n; i++) { for(J=head[i]; j!=-1; J=edge[j].next) {intV=EDGE[J].V;if(Belong[v]!=belong[i]) {in[belong[v]]++; out[belong[i]]++; } } } for(i=1; i<=ans; i++) {if(!in[i]) incnt++;if(!out[i]) outcnt++; }printf("%d\n", Max (incnt,outcnt)); }return 0;} *
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2767-proving equivalences (strong unicom + pinch point)