UVA 315 Network (no-map-cut point)

Source: Internet
Author: User

The main idea: to give you an no-map, the number of cut points. Input data first row one n means there are n points followed by a number of lines, until read into a 0, the entire map read into the end, and then read into a 0, the end of the file data.  Each row has the first number a, which means that the next number is connected to a. Knowledge Summary: Cut point: In the undirected connected graph, if a point is deleted, the graph becomes disconnected, then the point is called a cut point. Here the cutting point and the bridge are the concept of the non-direction diagram, we do not confuse here. To cut points a vertex u is a cut point, when and only if satisfies (1) or (2) (1) U is a root, and U has more than one subtree. (2) U is not a root, and satisfies the presence (U,V) as a branch edge (or parent-child edge, that is, U is the father of V in the search tree), making DFN (U) <=low (v). (That is, V has no way to bypass the U-point to reach a smaller point than U DFN) Note: The tree mentioned here refers to the search tree under DFS. Cut point Tarjan Low and dfndfn[u] definition is similar to the previous, but low[u] defined as U or u in a subtree can be traced through non-parent-child edge of the first node of the DFS start time in the Tarjan algorithm to cut point we want to add an array father[u], Determine whether the two are parent-child side
#include <cstdio> #include <cstdlib> #include <cmath> #include <iostream> #include < algorithm> #include <cstring> #include <vector>using namespaceStd;#define MAXN 10005intDfn[Maxn];/// represents the first time to traverse to this pointintLow[Maxn];/// The earliest point of time before this point can be reachedintFather[Maxn];/// Save this node's father nodeintN,M,Time,Top;///time point in time, top for stack operationsVector<Vector<int> >G;voidInit(){G.Clear();G.Resize(N+1);Memset(Low,0,sizeof(Low));Memset(Dfn,0,sizeof(Dfn));Memset(Father,0,sizeof(Father));Time =0;}voidTarjan(intU,intFa){Low[U] =Dfn[U] = ++Time;Father[U] =Fa;intLen =G[U].Size(),V; for(intI=0;I<Len;I++) {V =G[U][I];if(!Dfn[V]) {Tarjan(V,U);Low[U] =Min(Low[U],Low[V]); }else if(Fa !=V)if we write here Low[u] = min (Low[v], low[u]), then it is equivalent to the node before v backLow[U] =Min(Dfn[V],Low[U]); }}voidSolve(){/** cut point a vertex u is a cut point, when and only if satisfies (1) or (2) (1) U is a root, and U has more than one subtree. (2) U is not a root, and satisfies the presence (U,V) as a branch edge (or parent-child edge, that is, U is the father of V in the search tree), making DFN (U) <=low (v). (That is, V has no way to bypass the U-point to reach a smaller point than U DFN) Note: The tree mentioned here refers to the search tree under DFS */intRootson =0,Ans =0;/// root node number of sonsBOOLCut[Maxn] = {false};/// tag array to determine if this point is a cut pointTarjan(1,0); for(intI=2;I<=N;I++) {intV =Father[I];if(V ==1)/// I also say I's father is the root nodeRootson ++;else if(Dfn[V] <=Low[I])Cut[V] =true; } for(intI=2;I<=N;I++) {if(Cut[I])Ans ++; }if(Rootson>1)Ans++;Printf("%d\n",Ans);}intMain(){ while(scanf("%d", &N),N) {intA,B;CharCh;Init(); while(scanf("%d", &A),A) { while(scanf("%d%c",&B,&Ch)) {G[A].Push_back(B);G[B].Push_back(A);if(Ch ==' \ n ') Break; } }Solve(); }return0;}

UVA 315 Network (no-map-cut point)

Related Article

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.