Topic Link: Portal
The main idea: a pair of undirected graphs, asked how many nodes to meet the deletion of the node after the diagram is not connected, for each node satisfies the condition, the output node number and delete node will be divided into several connected blocks. Output no SPF nodes if no node is satisfied
Topic Idea: Tarjan algorithm to find the joint point of entry questions (also available matrix storage map)
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 100000007 - #defineINF 0x3f3f3f3f - #defineN 1000005 in #defineMAXN 1000050 -typedefLong LongLL; totypedef pair<int,int>PII; + - intn,m,head[1001],hcnt,son,num; the intdfn[1001],low[1001],area[1001],vis[1001]; * intDeep ; $ structnode{Panax Notoginseng intTo,next; - Node () {} theNode (intAintb): to (a), next (b) {} +}node[2000800]; AInlinevoidAddintXinty) { thenode[hcnt]=Node (y,head[x]); +head[x]=hcnt++; - } $ $ voidinit () { -num=0;///number of the maximum node -Hcnt=0; thedeep=1;///Depth preference of depth search tree (number of searches) -son=0;///record the number of children in the root nodeWuyilow[1]=dfn[1]=1;///Low indicates the minimum depth priority that the node can reach through the child and back edge theMST (head,-1);///DFN indicates the depth priority of a node -MST (VIS,0); WuMST (area,0);///after deleting a node, the graph is divided into several pieces. -vis[1]=1;///flag whether the node has visited About } $ - voidDfsintx) { - for(intI=head[x];~i;i=Node[i].next) { - intE=node[i].to; A if(Vis[e]) low[x]=Min (Low[x],dfn[e]); + Else{ thevis[e]=1; -dfn[e]=low[e]=++Deep ; $ DFS (e); thelow[x]=Min (Low[x],low[e]); the if(low[e]>=Dfn[x]) { the if(x==1) ++Son; the Else++Area[x]; - } in } the } the } About the intMain () { the intI,j,group,case=0, x, y; the while(SCANF ("%d", &x)!=eof&&x) { + init (); -num=Max (num,x); thescanf"%d",&y);Bayinum=Max (num,y); the Add (x, y); the Add (y,x); - while(SCANF ("%d", &x) &&x) { -num=Max (num,x); thescanf"%d",&y); thenum=Max (num,y); the Add (x, y); the Add (y,x); - } the if(case) printf ("\ n"); theprintf"Network #%d\n",++Case ); theDfs1);94 if(son>1) area[1]=son-1; the intflag=0; the for(i=1; i<=num;++i)if(Area[i]) { theflag=1;98printf"SPF node%d leaves%d subnets\n", i,area[i]+1); About } - if(!flag) printf ("No SPF nodes\n");101 }102 return 0;103}
ZOJ1119 (SPF)