"Aha algorithm"--cutting point, cutting edge, two-part diagram

Source: Internet
Author: User

In this article, we briefly introduce the concepts related to the cutting point, cutting edge and dichotomy diagram of the solution graph.

Cut point:

For the connected undirected graph G with n points and m edges, if the vertex VI is removed (and the edge is removed at the same time) so that G is no longer connected, then the VI is a cut point.

By its definition, it is not difficult to determine whether a point is a cut point, but now we face the question is, how to give a figure g, code to let the computer solve the cut point?

First we consider the question of determining what the indicator of a point is. We use the human brain to determine whether it is a cut point, in fact, using a very vague visual effect, that is, "by removing the point of view is connected", and if you want to judge by the computer, it requires very quantitative judgment conditions.

We consider the perspective of depth-first search to find such a condition, using the DFS traversal graph, the resulting sub-graph will essentially get a spanning tree, we take out two adjacent points VI, VJ,VI is the parent node of VJ. We go back to the deep search traversal, assuming that we are currently traversing to VJ, if we can find a return from VJ to the V1, v2 ... Nodes, then this indicates that removing VI will not affect the connectivity of the remaining graphs.

We seem to have found something, but the judgment relationship is somewhat vague.

We borrowed the concept-timestamp, the depth-first search process, we record the order of access nodes, we use num[i] to represent the time stamp of Node vi, that is, during the deep search traversal of the first few access to the VI node. Using this tool, we consider whether we can express the relationship described above with a quantified expression? Seems to be a little stretched ah, we might as well set an array low[i], to express the VI not through the DFS tree parent node can reach the smallest time stamp node (well understood, very awkward), based on this tool, we can see the above conditions of judgment, You can use such an expression as a concise generalization:

Low[i] < Num[i]

So now our first question seems to be the solution of N-node low[], num[].

First, for num[], which is the timestamp record, it is not difficult. For the solution of low[] array, we need to move some brains. We simulate the traversal process, currently traversing to the VI point, we access all the points with the VI connected to VJ, there are two cases.

1.vj visited, we have been the timestamp, then we need to update low[i], that is low[i] = Min{num[j] | VJ and VI connectivity}.

2.VJ has not been visited, then we continue to deep search the process of traversing the point.

After the completion of the traversal, also completed the num[], low[] solution, we use the deep search of the backtracking process, to complete the judgment can be.

One thing to note here is that for the root node of a graph, that is, the point at which Dfs starts (as v1) is actually not satisfied with the above-mentioned judgments, we need special judgment, the child is the root node of the number of subtrees, then V1 is a cut point is the necessary condition is, child = 2.

The simple reference code is as follows.

#include <cstdio>#include<algorithm>using namespacestd;intN, M, e[9][9], root;intnum[9], low[9], flag[9],index;intMinintAintb) {     returnA < b?a:b;}voidDfsintCur,intfather) {    intChild =0, I, J; Index++; Num[cur]=index; Low[cur]=index;  for(i =1; I <= n;i++)      {            if(E[cur][i] = =1)            {                   if(Num[i] = =0)//first Case{ Child++;                         DFS (i,cur); Low[cur]= Min (Low[cur], low[i]);//Backtracking process: Judging the cutting point                         if(cur! = root && low[i] >=Num[cur]) flag[cur]=1; Else if(cur = = Root && Child = =2) Flag[cur]=1; }                                       Else if(I! = father)//The second case{Low[cur]=min (low[cur], num[i]); }            }      }}intMain () {intI, J, X, y; scanf ("%d%d",&n,&m);  for(i =1; I <= n;i++)           for(j =1; J <= n;j++) E[i][j]=0;  for(i =1; I <= m;i++) {scanf ("%d%d",&x,&y); E[x][y]=1; E[Y][X]=1; } Root=1; DFS (1, Root);  for(i =1; I <= n;i++)     {           if(Flag[i] = =1) printf ("%d", i); }     return 0;}

"Aha algorithm"--cutting point, cutting edge, two-part diagram

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.