Diagram of Unicom-cut point and bridge

Source: Internet
Author: User

Cut Point

Dfs search tree : When using DFS to traverse graphs, we can get a DFS search tree according to the different traversal order.

Tree Edge : (called a parent-child edge ), which can be understood as the edge through which an unreachable node is accessed during a DFS process.

Back Edge : ( atavistic Edge , back Edge ), which can be understood as the edge through which a node has been accessed during the DFS process.

The algorithm was invented by R.tarjan. Observing the DFS search tree, we can see that there are two types of nodes that can be cut points:

    1. to the root node u, if it has two or more subtree, then the root node U is a cut point;
    2. For non-leaf node U (non-root node), if the node with a subtree does not have a back edge to the ancestor node of U, the node of the root node and the subtree of U are no longer connected after removing U, then node u is the cut point.

Http://cogs.pro/cogs/problem/problem.php?pid=8

#include <cstdio>#include<algorithm>using namespacestd;structedge{intTo,next;} edge[10005];intfi[ the],top,low[ the],fa[ the],dfn[ the],kid[ the];BOOLvis[ the],cut[ the];voidAdd_edge (int  from,intTo ) {edge[++top].next=fi[ from],fi[ from]=top,edge[top].to=to ; edge[++top].next=fi[to],fi[to]=top,edge[top].to= from;}voidDfsintx) {    //Record DFS traversal order    Static intCounter =0; DFN[X]=low[x]=++counter; VIS[X]=1; if(x==4) x=4;  for(intto = fi[x];to;to=Edge[to].next) {        intv=edge[to].to; if(!vis[v]) {//node v is not accessed, then (U,V) is a tree edgefa[v]=x;kid[x]++;            DFS (v); LOW[X]=min (low[x],low[v]); if(Low[v]>=dfn[x]) cut[x]=1; }        Else if(V!=fa[x]) {//node v has been accessed, then (U,V) is a back edgelow[x]=min (low[x],dfn[v]); }    }}intMain () {Freopen ("gd.in","R", stdin); Freopen ("Gd.out","W", stdout); intn,a,b,ans=0; scanf ("%d",&N);  while(~SCANF ("%d%d",&a,&b))    Add_edge (A, b); DFS (1); if(kid[1]<2) cut[1]=0;  for(intI=1; i<=n;i++){        if(Cut[i]) ans++; } printf ("%d\n", ans);  for(intI=1; i<=n;i++){        if(Cut[i]) printf ("%d\n", i); }    return 0;}
Find a bridge

For an edge (U,V), U is an ancestor, and if all the subtrees of V do not point to a point that is first traversed (U,V) is the bridge

Unicom-cut points and bridges for graphs

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.