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 11005 in #defineMAXN 5005 -typedefLong LongLL; totypedef pair<int,int>PII; + -stack<int>SK; the intn,m,hcnt,deep,block,leaf; * intD[MAXN],DFN[MAXN],LOW[MAXN],HEAD[MAXN]; $ intCOLOR[MAXN],VIS[MAXN];Panax Notoginseng structnode{ - intTo,next; the Node () {} +Node (intAintb): to (a), next (b) {} A}node[n<<1]; the +InlinevoidAddintXinty) { -node[hcnt]=Node (y,head[x]); $head[x]=hcnt++; $ } - -Inlinevoidinit () { the while(!sk.empty ()) Sk.pop (); -MST (VIS,0);WuyiMST (head,-1); theMST (D,0); -MST (DFN,0); Wuhcnt=deep=0; -block=leaf=0; About } $ - voidDfsintXintFA) { - intflag=1;///This is not necessary, it's effective when there are heavy edges . - Sk.push (x); Avis[x]=1; +low[x]=dfn[x]=++Deep ; the for(intI=head[x];~i;i=Node[i].next) { - intE=node[i].to; $ if(E==fa&&flag) {flag=0;Continue;} the if(Vis[e]) low[x]=min (low[x],dfn[e]); the Else if(!Dfn[e]) { the DFS (e,x); thelow[x]=min (low[x],low[e]); - } in } the if(low[x]==Dfn[x]) { the++block;///Pinch point About intCo; the Do{ theco=sk.top (); Sk.pop (); thevis[co]=0; +color[co]=Block; -} while(co!=x); the }Bayi } the the intMain () { - intI,j,group,case=0, x, y; - while(SCANF ("%d%d", &n,&m)! =EOF) { the init (); the for(i=0; i<m;++i) { thescanf"%d%d",&x,&y); the Add (x, y); - Add (y,x); the } the for(i=1; i<=n;++i) { the if(!dfn[i]) DFS (i,-1);94 } the if(block==1) {printf ("0\n");Continue;}///determine if it is already a double connected graph the for(i=1; i<=n;++i) the for(j=head[i];~j;j=Node[j].next) {98 intE=node[j].to; About if(color[i]!=Color[e]) -++d[color[i]];///The D array retains the degree of each point after the indent .101 }102 for(i=1; i<=block;++i) {103 if(d[i]==0) leaf+=2;///if there are isolated points, the leaf node plus 2104 Else if(d[i]==1)++Leaf; the }106printf"%d\n", (leaf+1)/2);107 }108 return 0;109}
Side Double Unicom component (construction side double unicom)