HDU3594 Cactus ([good title] strong Connectivity Cactus diagram)

Source: Internet
Author: User

Test instructions: Judging is not the definition of Cactus diagram, Cactus diagram,
1. First of all, strong connectivity
2. Any of the times can only belong to a circle.
Analysis of cactus graphs

#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <set>#include <map>#include <string>#include <cstring>#include <stack>#include <queue>#include <vector>#include <cstdlib>#define Lson (rt<<1), L,m#define Rson (rt<<1|1), M+1,r#define M ((l+r) >>1)#define CL (A, B) memset (A,b,sizeof (a));#define LL Long Long#define P pair<int,int>#define X First#define Y Second#define PB Push_back#define FREAD (ZCC) freopen (ZCC, "R", stdin)#define FWRITE (ZCC) freopen (ZCC, "w", stdout)using namespace STD;Const intmaxn=20005;Const intinf=999999; vector<int>G[MAXN];intLOW[MAXN],DFN[MAXN],S[MAXN],BELONG[MAXN];BOOLINS[MAXN];intNum,cnt,top;BOOLOkBOOLVIS[MAXN];voidDfsintu) {low[u]=dfn[u]=++num; ins[u]=true; S[top++]=u;intN=g[u].size ();intsum=0; for(intI=0; i<n;i++) {intV=g[u][i];if(Vis[v]) ok=false;//Nature 1        if(!dfn[v]) {DFS (v);if(Low[v]>dfn[u]) ok=false;//Nature 2            if(Low[v]<dfn[u]) sum++;if(sum==2) ok=false;        Low[u]=min (Low[u],low[v]); }Else if(Ins[v])            {low[u]=min (dfn[v],low[u]); sum++;if(sum==2) ok=false;//Nature 3}    }if(Low[u]==dfn[u]) {intv=-1; cnt++; while(U!=V)            {V=s[--top]; ins[v]=false;        belong[v]=cnt; }} vis[u]=true;}voidTarjan (intN) {cl (DFN,0); CL (INS,false); CL (Belong,0); CL (VIS,false); ok=true; Num=top=cnt=0; for(intI=1; i<=n;i++) {if(!dfn[i]) DFS (i); }}intMain () {intTscanf("%d", &t); while(t--) {intNscanf("%d", &n); for(intI=0; i<=n;i++) {g[i].clear (); }intx, y; while(scanf("%d%d", &x,&y) && (x+y)) {x++;y++;        G[X].PB (y); } Tarjan (n);printf("%s\n", cnt==1&&ok?"YES":"NO"); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU3594 Cactus ([good title] strong Connectivity Cactus diagram)

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.