POJ1523 SPF (cut point)

Source: Internet
Author: User

The topic asks for all the cut points of an undirected graph, and the output deletes the cut points and forms several connected components. Using the Tarjan algorithm:

Over Dfs, a depth-first spanning tree is constructed, and the edges in the original graph are divided into two types: the edge of the tree (the edge on the spanning tree) and the anti-ancestor Edge (not the edge on the spanning tree).

By the way, the DFS sequence of each node Dfn[u] and each node can be reached along the atavistic edge of it and its son the smallest DFS order Low[u].

One point is the cut point and only if--

    • This point is the root of the spanning tree and has X (x>=2) sub-trees, and the X-connected component is formed after the point is deleted.
    • This point is not a root, and its existence x (X>=1) son's low value is less than equal to the DFN value of the point, after the deletion of the point, the formation of x+1 connected components.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 #defineMAXM 1111*1111*26 #defineMAXN 11117 structedge{8     intV,next;9 }EDGE[MAXM];Ten intHead[maxn],ne; One voidAddedge (intUintv) { AEdge[ne].v=v; Edge[ne].next=head[u]; head[u]=ne++; - } - intDN,DFN[MAXN],LOW[MAXN],SON[MAXN]; the voidDfsintu) { -dfn[u]=low[u]=++DN; -      for(intI=head[u]; i!=-1; I=Edge[i].next) { -         intv=edge[i].v; +         if(Dfn[v]) { -low[u]=min (low[u],dfn[v]); +             Continue; A         } at Dfs (v); -         if(u==1) ++Son[u]; -         Else if(Low[v]>=dfn[u]) + +Son[u]; -low[u]=min (low[u],low[v]); -     } - } in BOOLoutput () { -     BOOLflag=0; to     if(son[1]>=2) printf ("SPF node 1 leaves%d subnets\n", son[1]), flag=1; +      for(intu=2; u<= +; ++u) { -         if(Son[u]) printf ("SPF node%d leaves%d subnets\n", u,son[u]+1), flag=1; the     } *     returnFlag; $ }Panax Notoginseng intMain () { -     intu,v,t=0; the      for(;;) { +         BOOLflag=1; ANe=0; thememset (head,-1,sizeof(head)); +          while(~SCANF ("%d", &u) &&u) { -scanf"%d",&v); $ Addedge (u,v); Addedge (v,u); $flag=0; -         } -         if(flag) Break; thedn=0; -memset (DFN,0,sizeof(DFN));WuyiMemset (son,0,sizeof(son)); theDfs1); -printf"Network #%d\n",++t); Wu         if(!output ()) puts ("No SPF Nodes"); -Putchar ('\ n'); About     } $     return 0; -}

POJ1523 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.