Transmission Door
Title: Output Depth first spanning tree
/*data structure: adjacency table storage Diagram Program Description: For the sake of simplicity, set the type of the node is integral type, set visited[],num[].low[],parent[] as the global variable, for the first order number num[], set the global variable counter and initialized to 1. Set the root variable for easy processing of the root node alone. */#include<cstdio>#include<vector>#include<algorithm>using namespacestd;Const intMax_n = -; Vector<int>Graph[max_n];vector<int>Artpoint;intNum[max_n], Low[max_n], parent[max_n];intCounter =1;intRoot;BOOLVisited[max_n];voidInit ();//initialization DiagramvoidFindart (intV);//find the second type of cut pointvoidPrintartpoint ();//Print all cut points (the first type of cutting point is handled separately here)intMain () {Init (); Findart (root); Printartpoint (); return 0;}voidPrintartpoint () {intRootchild =0;//number of children in the root node for(inti =0; I < graph[root].size (); i++)//calculate the number of children in the root node { if(Parent[graph[root][i]] = =root) Rootchild++; } if(Rootchild >1)//root node The number of children greater than 1 is the cut pointArtpoint.push_back (root); for(inti =0; I < artpoint.size (); i++) printf ("%d\n", Artpoint[i]);}voidInit () {intA, B; Root=1; while(SCANF ("%d%d", &a, &b)! =EOF) {Graph[a].push_back (b); Graph[b].push_back (a); Visited[a]=false; VISITED[B]=false; }}voidFindart (intv) {Visited[v]=true; LOW[V]= Num[v] = counter++;//situation (1) for(inti =0; I < graph[v].size (); i++) { intW =Graph[v][i]; if(!visited[w])//Tree Side{Parent[w]=v; Findart (w); if(Low[w] >= num[v] && v! =root) artpoint.push_back (v); LOW[V]= Min (Low[v], low[w]);//situation (3) } Else if(Parent[v]! = W)//Fallback Edge{Low[v]= Min (Low[v], num[w]);//situation (2) } }}
Operation Result:
"Figure: C + +" deep-formed tree