Tarjan calculates the cut point hoj1007spf

Source: Internet
Author: User
// Cut point hoj1007 # include <cstdio> # define min (A, B) A> B? B: A; # define max (A, B) A> B? A: B; const int v = 1001; struct edge {int next, to;} edge [V * V]; int CNT, idx; int cut [v], n, head [v]; int low [v], dfn [v]; void Init () {CNT = 0; idx = 0; For (INT I = 1; I <= V; I ++) {head [I] =-1; low [I] = 0; dfn [I] = 0; cut [I] = 0 ;}} void addedge (INT U, int v) {edge [CNT]. to = V; edge [CNT]. next = head [u]; head [u] = CNT ++;} void Tarjan (int u, int FA) {LOW [u] = dfn [u] = (++ idx); For (int K = head [u]; k! =-1; k = edge [K]. Next) {int v = edge [K]. To; If (V = FA) continue; If (dfn [v]! = 0) {LOW [u] = min (dfn [v], low [u]); continue;} Tarjan (v, U ); low [u] = min (low [u], low [v]); If (low [v]> = dfn [u]) Cut [u] ++; // unable to access nodes smaller than u} If (Fa! = 0) Cut [u] ++;} int main () {// freopen ("a.txt", "r", stdin); int A, B; int num = 0; while (scanf ("% d", & )! = EOF) {if (a = 0) break; Init (); n = 0; scanf ("% d", & B); n = max (, n); n = max (B, n); addedge (a, B); addedge (B, A); While (1) {scanf ("% d ", & A); if (a = 0) break; scanf ("% d", & B); n = max (A, n); n = max (B, n); addedge (a, B); addedge (B, A);} Tarjan (1, 0); bool flag = false; If (Num> 0) printf ("\ n"); printf ("Network # % d \ n", ++ num); For (INT I = 1; I <= N; I ++) if (cut [I]> 1) {printf ("SPF node % d leaves % d subnets \ n", I, cut [I]); flag = T Rue;} If (! Flag) printf ("No SPF nodes \ n");} return 0 ;}

Related Article

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.