Network--uva--315 (poj--1144) (non-point graph for connecting graph template problem)

Source: Internet
Author: User

Link:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 251

http://poj.org/problem?id=1144

Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#problem/B

Code:

#include <cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>using namespacestd;#defineMAXN 10005intDFN[MAXN];///represents the first time to traverse to this pointintLOW[MAXN];///The earliest point of time before this point can be reached .intFATHER[MAXN];///Save this node's father nodeintN, M, time, top;///time point, 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 (intUintFA) {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 wrote here Low[u] = min (Low[v], low[u]), then it would be equivalent to the node before V returned to VLow[u] =min (Dfn[v], low[u]); }}voidsolve () {/** To cut points a vertex u is a cut point, when and only if satisfies (1) or (2) (1) U is the 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;///number of sons of the root node    BOOLCUT[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)///The father of I is the root node, too .Rootson + +; 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 (); }    return 0;}

Network--uva--315 (poj--1144) (non-point graph for connecting graph template problem)

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.