Solving the problem of edge-to-double connectivity (structural edge dual connected graph) POJ3352 (Road construction)

Source: Internet
Author: User

Topic Link: Portal

The main topic: give you a pair of non-direction, ask at least how many edges to make the diagram become a double unicom

Topic Idea: Tarjan algorithm to shrink point, after the reduction of the number of leaf nodes of 1 degrees, need to add the number of edges (leaf+1)/2

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cmath>5#include <algorithm>6#include <cstring>7#include <stack>8#include <cctype>9#include <queue>Ten#include <string> One#include <vector> A#include <Set> -#include <map> -#include <climits> the #defineLson Root<<1,l,mid - #defineRson Root<<1|1,mid+1,r - #defineFi first - #defineSe Second + #definePing (x, y) ((x-y) * (x-y)) - #defineMST (x, y) memset (x,y,sizeof (x)) + #defineMCP (x, y) memcpy (x,y,sizeof (y)) A #defineMin (x, y) (x<y?x:y) at #defineMax (x, y) (x>y?x:y) - using namespacestd; - #defineGamma 0.5772156649015328606065120 - #defineMOD 1000000007 - #defineINF 0x3f3f3f3f - #defineN 5005 in #defineMAXN 10005 -typedefLong LongLL; totypedef pair<int,int>PII; +  -vector<int>v[1005]; the intN,m,hcnt,deep; * structnode{ $     intTo,next;Panax Notoginseng Node () {} -Node (intAintb): to (a), next (b) {} the }node[n]; + intHead[n],vis[n],low[n],dfn[n]; A intD[n]; the  +InlinevoidAddintXinty) { -node[hcnt]=Node (y,head[x]); $head[x]=hcnt++; $ } -  -Inlinevoidinit () { theMST (D,0); -MST (VIS,0); vis[1]=1;WuyiMST (head,-1); theHcnt=0; -deep=1; Wulow[1]=dfn[1]=1; - } About  $ voidDfsintXintfather) { -      for(intI=head[x];~i;i=Node[i].next) { -         intE=node[i].to; -         if(E==father)Continue; A         if(Vis[e]) low[x]=min (low[x],dfn[e]); +         Else{ thevis[e]=1; -low[e]=dfn[e]=++Deep ; $ DFS (e,x); thelow[x]=min (low[x],low[e]); the         } the     } the } -  in intMain () { the     intI,j,group,case=0, x, y; the      while(SCANF ("%d%d", &n,&m)! =EOF) { About          for(i=0; i<=n;++i) V[i].clear (); the init (); the          while(m--){ thescanf"%d%d",&x,&y); + Add (x, y); - Add (y,x); theV[x].push_back (y);///Two-point UnicomBayiV[y].push_back (x);///used to calculate degrees after a pinch point the         } theDfs1,-1);///Tarjan Algorithm -         intleaf=0; -          for(i=1; i<=n;++i) the         if(V[i].size ()) the          for(j=0; J<v[i].size (); + +j) { the             intE=V[i][j]; the             if(low[i]!=Low[e]) -d[low[i]]++; the         } the          for(i=0; i<=deep;++i) the             if(d[i]==1)++Leaf;94printf"%d\n", (leaf+1)/2); the     } the     return 0; the}

Solving the problem of edge-to-double connectivity (structural edge dual connected graph) POJ3352 (Road construction)

Related Article

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.