Test instructions: Known undirected graph, ask to add the least edge to make it a side double connected graph
Idea: It is obvious to indent the point into a tree, add the least side to make the edge of a tree connected
Here is the conclusion: for a tree to add (1+leaf) >>1 strip without the edge can be structured into a double-connected graph, the construction method is obvious (brain repair
216k63msc++1754b #include <cstdio> #include <iostream> #include <cstring> #include <alg Orithm> using namespace std; const int N = 1010; struct node {int v,next; }es[n*n]; int head[n]; int n,m; int low[n],dfn[n],index; int indeg[n]; void Ini () {memset (head,-1,sizeof (head)); memset (dfn,0,sizeof (DFN)); index=0; memset (indeg,0,sizeof (indeg)); } void Tarjan (int u,int pa) {dfn[u]=low[u]=++index; for (int i=head[u];~i;i=es[i].next) {int v=es[i].v; if (dfn[v]==0) {Tarjan (v,u); Low[u]=min (Low[u],low[v]); } if (V!=PA) low[u]=min (Low[u],low[v]); }} int main () {while (~scanf ("%d%d", &n,&m)) {ini (); for (int i=1;i<=m;i++) {int u,v; scanf ("%d%d", &u,&v); ES[i].v=v; Es[i].next=head[u]; Head[u]=i; Es[i+m].v=u; ES[I+M].NEXT=HEAD[V]; Head[v]=i+m; } for (int i=1;i<=n;i++) if (dfn[i]==0) Tarjan (i,-1); for (int u=1;u<=n;u++) {for (int i=head[u];~i;i=es[i].next) { int v= es[i].v; if (Low[v]==low[u]) continue; indeg[low[u]]++; }} int leaf=0; for (int i=1;i<=n;i++) if (indeg[i]==1) leaf++; printf ("%d\n", (leaf+1)/2); } return 0; }
POJ 3352 Road Construction (conclusion of adding a double connected graph with the least side construction edge)