POJ-1523 SPF (cut point)

Source: Internet
Author: User

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)

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.