The main idea: give a picture, ask to cut points, the number of connected components is how many
Problem-solving ideas: cut points of water problems, set template can be
Had to spit out the slot for input.
#include <cstdio>#include <cstring>#define MIN (a) < (b) ( A):(B))#define N 1010#define M 2000010structedge{intTo, next;} E[M];intHead[n], Num[n], pre[n], lowlink[n];intTot, dfs_clock, root;BOOLIscut[n];voidDfsintUintFA) {Lowlink[u] = pre[u] = ++dfs_clock;intChild =0; for(inti = Head[u]; I! =-1; i = e[i].next) {intv = e[i].to;if(!pre[v]) {child++; DFS (v, u); Lowlink[u] = min (lowlink[u],lowlink[v]);if(U = = root && child >1) || (U! = root && pre[u] <= lowlink[v])) {num[u]++; } }Else if(v! = FA) {Lowlink[u] = min (Lowlink[u], pre[v]); } }}intCAS =1;voidSolve () {memset(Pre,0,sizeof(pre));memset(Num,0,sizeof(num)); Dfs_clock =0; for(inti =1; I <= +; i++) {if(!pre[i] && head[i]! =-1) {root = i; DFS (i,-1); } }printf("Network #%d\n", cas++);BOOLFlag =false; for(inti =1; I <= +; i++)if(Num[i]) {printf("SPF node%d leaves%d subnets\n", I, Num[i] +1); Flag =true; }if(!flag) {printf("No SPF nodes\n"); }}voidAddedge (intUintV) {e[tot].to = v; E[tot].next = Head[u]; Head[u] = tot++; u = u ^ v; v = u ^ v; u = u ^ v; E[tot].to = v; E[tot].next = Head[u]; Head[u] = tot++;}intMain () {intA, B;BOOLFlag =false; while(scanf("%d", &a)! = EOF && a) {if(flag)printf("\ n"); Flag =true;memset(Head,-1,sizeof(head)); tot =0;scanf("%d", &b); Addedge (A, b); while(scanf("%d", &a) && a) {scanf("%d", &b); Addedge (A, b); } solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ-1523 SPF (cut point)