#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;Const intmaxn=1111;//How many nodes are there?vector<int>G[MAXN];intVISITED[MAXN];//flag If the node has visitedintNode,edge;//number of verticesintTMPDFN;//The current depth-first search ordinal is logged in the DFS processintDFN[MAXN];//record Depth-first search ordinal for each vertexintLOW[MAXN];//The low value of each vertex, based on the value to determine if it is a joint pointintSon//How many children are at the root node, and if greater than or equal to 2, the root node is the joint pointintSUBNETS[MAXN];//record the number of connected components for each node (after the node is removed)voidinit () { for(intI=0; i<maxn;i++) g[i].clear (); low[1]=dfn[1]=1; TMPDFN=1; son=0; Memset (visited,0,sizeof(visited)); visited[1]=1; memset (Subnets,0,sizeof(subnets));}voidDfsintu) { for(intI=0; I<g[u].size (); i++) { intv=G[u][i]; if(!Visited[v]) {Visited[v]=1; TMPDFN++; dfn[v]=low[v]=TMPDFN; DFS (v); Low[u]=min (low[u],low[v]); if(low[v]>=Dfn[u]) { if(u!=1) subnets[u]++; if(u==1) son++; } } Elselow[u]=min (low[u],dfn[v]); }}intMain () {scanf ("%d%d", &node,&edge);//Enter the number of nodes and the number of edgesInit ();//Initialize for(intI=1; i<=edge;i++) { intu,v; scanf ("%d%d",&u,&v); //non-Tujian sideG[u].push_back (v); G[v].push_back (U); } //Solving cut pointsDfs1); //Compute root Node if(son>1) subnets[1]=son-1; for(intI=1; i<=node;i++) if(Subnets[i]) printf ("node%d is a cut point, and after deletion there are%d connected components \ n", i,subnets[i]+1); return 0;}
Tarjan algorithm for solving the cut-point template of undirected connected graphs