"Request" given an no-map, find the cut-point bridge in the diagram
"said in front" read so much, want to get started to understand the words really recommend "Listen to the rain thatched cottage" This article , combined with templates and the meaning of each array expression, at least I understand. Template I do not use her, is to hand over the Red Book template, anyway are the same thing;
"Several definitions"
- Dfs search tree : When using DFS to traverse graphs, we can get a Dfs search tree, as shown in (b), depending on the traversal order.
- Tree Edge : (or parent-child side ), as shown in the solid line in the search tree, can be understood as the edge that passes when accessing an unreachable node during a DFS process.
- Back Edge : (or atavistic edge , back Edge ), as shown in the dotted line in the search tree, can be understood as the edge that passes when you encounter an accessed node in a DFS process.
"Focus" DFS-based algorithms---> tarjan
- to the root node u, if it has two or more subtree, then the root node U is a cut point;
- For non-leaf node U (non-root node), if the node of its subtree does not have a back edge to the ancestor node of u, after deleting u, the node of the root node and the subtree of U are no longer connected; the node U is a cut point.
cur is the condition of cutting point : ①cur is root and has greater than one son; ②cur is not a root and cur has a son v make low[v] >= dfn[cur];
(cur, i) is the condition of the bridge : Low[i] > dfn[cur];
"Difficulty" for Dfn[max_v] and Low[max_v] array of understanding and simulation of its implementation process;
int // the depth at which node V is accessed int // node v can reach the depth of the earliest ancestor of the access time
For a detailed example see Yumbo master;
Template
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <vector>5#include <iostream>6 using namespacestd;7 Const intMax_v = +;8 Const intMax_e =1000000;9 Ten intVIS[MAX_V];//node v current access state, 0 means no access, 1 means in the stack, 2 means that you have visited One intDFN[MAX_V];//the depth at which node V is accessed A intLOW[MAX_V];//node v can reach the depth of the earliest ancestor of the access time - BOOLCut[max_v]; - BOOLBridge[max_v][max_v]; the //cur is the condition of the cutting point: ①cur is root and has greater than one son; ②cur is not a root and cur has a son v makes low[v]>=dfn[cur]; - //(cur, i) is the condition of the bridge: Low[i] > Dfn[cur]; - voidCur_bridge (intCurintFatherintDepintN//vertex:0~n-1 - { +Vis[cur] =1; -Dfn[cur] =DEP; +Low[cur] =DEP; A intChildren =0; at for(inti =0; I < n; i++) - { - if(Edge[cur][i])//nodes connected to the current node I - { - if(I! = Father && Vis[i] = =1)//I in the current stack, the description diagram has a ring, with the depth of I update the cur low value; - { in if(Dfn[i] < low[cur]) low[cur] = Dfn[i];//The depth of the earliest ancestor to which the node cur can be reached is updated to the depth of the node I being visited; - } to if(Vis[i] = =0)//I have not been visited, recursive access node I, and I can reach the earliest ancestors to update the low value of cur; + { -Cut_bridge (i, cur, dep+1, n); theChildren + +; * $ if(Low[i] < low[cur]) low[cur] =Low[i];Panax Notoginseng if(father = =-1&& Children >1) || (father = =-1&& Low[i] >= dfn[cur])//Judging the cut point -Cut[cur] =true; the if(Low[i] > Dfn[cut]) bridge[cur][i] = bridge[i][cur] =true;//judging the bridge + } A } the } +Vis[cur] =2; -}
"Go" "template" for cutting points and bridges