"Figure: C + +" deep-formed tree

Source: Internet
Author: User

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

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.