Cut Points and Bridges

① Cut point u, if and only if (1) or (2) are satisfied

 (1) u is the root of the tree, and u has more than one subtree.

 (2) u is not the root of the tree, and it satisfies the existence of (u, v) as the branch edge (or parent-child edge, that is, u is the father of v in the search tree), so that visit [u]<=goback[v] .


②The bridge has no directed edge (u, v) if and only if (u, v) is a branch edge, and satisfies visit [u]<goback[v] .



#include <iostream>

int min (int x, int y) {
 return x>y?y:x;
}

using namespace std;
int duan[1001]; //cut point marker
int qiao[1001];
int mark[1001]={0};
int n,m,k;
int visit[1001]={0}; //Visit order
int goback[1001]={0}; //The smallest point that a subtree can go back to
int p=1;
int parent[1001]={0};
int child[1001]={0}; //Record the number of children. Simply for the root node
int edge[1001][1001];

void DFS(int x)
 {
     mark[x]=1;
     visit[x]=goback[x]=p;
     p++;
     for(int i=1;i<=n;i++)
        if(edge[x][i]==1)
        {
            if(mark[i]==0)
            {
              DFS(i);
              parent[i]=x;
              goback[x]=min(goback[x],goback[i]);
              child[x]++;
              if(parent[x]==0&&child[x]>1) duan[x]=1;
              if(visit[x]<=goback[i]) duan[x]=1;
              if(visit[x]<goback[i]) qiao[x]=i;   //(x,i)为桥
            }
            else
            {
              if(i!=parent[x])
              goback[x]=min(goback[x],visit[i]);
            }
        }
 }





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325754547&siteId=291194637
cut