Title: http://poj.org/problem?id=1523
Topic Analysis:
Pay attention to the problem input input, prevent PE, the topic is to seek cutting points, and ask the cut point this connected graph into a few sub-graphs, is a template problem bar.
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<stack>#include<string>#defineN 10010using namespacestd;structnode{intX,y,next;} eg[2*N];intTt,head[n],dfn[n],low[n],ti,f[n];voidinit () {memset (head,-1,sizeof(head)); TT=0; TI=1; memset (DFN,0,sizeof(DFN)); Memset (F,0,sizeof(f));voidAddintXxintyy) {eg[tt].x=xx; Eg[tt].y=yy; Eg[tt].next=HEAD[XX]; HEAD[XX]=tt++;}voidTarjan (intUintFA) {Dfn[u]=low[u]=ti++; intChild=0; for(intI=head[u]; i!=-1; I=Eg[i].next) { intv=eg[i].y; if(V==FA)Continue; if(!Dfn[v]) { Child++; Tarjan (V,u); Low[u]=min (low[u],low[v]); if(low[v]>=dfn[u]&&fa!=-1) {F[u]++; } } Else //No- show graph does not span the edge{Low[u]=min (dfn[v],low[u]); } } if(fa<0&&child>1) f[u]=child-1;}intMain () {intxx,yy,u,v,k=0, Z; while(SCANF ("%d", &u)!=eof&&u) {init (); scanf ("%d",&v); Z=Max (U,V); Add (U,V); Add (V,u); while(SCANF ("%d", &xx)!=eof&&xx) {scanf ("%d",&yy); Z=Max (Z,max (XX,YY)); Add (XX,YY); Add (YY,XX); } Tarjan (1,-1); printf ("Network #%d\n",++K); intsum=0; for(intI=1; i<=z; i++) { if(F[i]) {sum++; printf ("SPF node%d leaves%d subnets\n", i,f[i]+1); } } if(sum==0) printf ("No SPF nodes\n"); printf ("\ n"); } return 0;}
POJ1523:SPF (non-connecting graph for cutting point)