Title Address:
pid=2767 ">hdu 2767
Test instructions: Give a picture of the map. Ask for a minimum number of edges to make the diagram strong.
Idea: The strong connected component of this graph is first asked. assumed to be 1. The output is 0 (proving that the graph does not need to have an edge that is strongly connected). Otherwise, the indent point.
Traverse all sides of the original. Suppose that 2 points are in different strong connected components, and build edges, forming a new picture. Statistics the in and out of the midpoint of the new graph, the take-in degree equals 0 and the maximum value of the out degree equals 0 (since the strong connected indent point is obtained. The whole picture becomes a non-loop, forward graph. To make it strong and connected. Just need to =0 and out of the degree of =0 Point plus edge can be, to ensure that there is no entry and the degree of 0 points, so take the two maximum value)
PS: Add the meaning of indentation: when we ask for strong connected components, we make a mark for each vertex, mark which of the vertices belongs to which strong link component, and then the point that belongs to the same strong connected component can be regarded as the same point.
This is called the "pinch point."
*#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;} *
HDU 2767-proving equivalences (strong unicom + pinch point)