hdu-1269 Maze Castle (strong connected nude)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1269

Determine whether a graph is strongly connected, and then determine whether the vertex count is 1 after the pinch point.

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <vector>5#include <cstring>6#include <algorithm>7#include <string>8#include <Set>9#include <functional>Ten#include <numeric> One#include <sstream> A#include <stack> -#include <map> -#include <queue> the  - #defineCL (arr, Val) memset (arr, Val, sizeof (arr)) -  - #definell Long Long + #defineINF 0x7f7f7f7f - #defineLC L,m,rt<<1 + #defineRC M + 1,r,rt<<1|1 A #definePi ACOs (-1.0) at  - #defineL (x) (x) << 1 - #defineR (x) (x) << 1 | 1 - #defineMID (L, R) (L + R) >> 1 - #defineMin (x, y) (x) < (y)? (x): (y) - #defineMax (x, y) (x) < (y)? (y): (x) in #defineE (x) (1 << (x)) - #defineIabs (x) (x) < 0? -(x): (x) to #defineOut (x) printf ("%i64d\n", X) + #defineLowbit (x) (x) & (-X) - #defineRead () freopen ("A.txt", "R", stdin) the #defineWrite () freopen ("Dout.txt", "w", stdout); *  $ using namespacestd;Panax Notoginseng #defineN 10100 - //n is the maximum number of points the #defineM 100100 + //m is the maximum number of sides A intN, M;//N M is the number of points and sides the  + structedge{ -     int  from, to, NEX; $     BOOLSign//whether it is a bridge $}edge[m<<1]; - intHead[n], edgenum; - voidAddintUintV) {//the beginning and end of the edge theEdge E={u, V, Head[u],false}; -Edge[edgenum] =E;WuyiHead[u] = edgenum++; the } -  Wu intDfn[n], Low[n], Stack[n], top, time;//Low[u] is the dfn[v of the point set {U-point and subtree in the root of the U-point (all reverse arcs) that can point to (the nearest ancestor V from the root ) (i.e., V-point timestamp) - intTaj//connecting branch designator, starting from 1 About intBelong[n];//Belong[i] represents the connected branch where I point belongs $ BOOLInstack[n]; -vector<int> Bcc[n];//marking starting from 1 -  - voidTarjan (intU,intFA) { ADfn[u] = Low[u] = + +Time ; +Stack[top + +] =u; theInstack[u] =1 ; -  $      for(inti = Head[u]; ~i; i =Edge[i].nex) { the         intv =edge[i].to; the         if(Dfn[v] = =-1) the         { the Tarjan (V, u); -Low[u] =min (Low[u], low[v]); in             if(Dfn[u] <Low[v]) the             { theEdge[i].sign =1;//to cut the bridge . About             } the         } the         Else if(Instack[v]) Low[u] =min (Low[u], dfn[v]); the     } +     if(Low[u] = =Dfn[u]) { -         intNow ; theTaj + +; Bcc[taj].clear ();Bayi          Do{ thenow = stack[--top]; theInstack[now] =0 ; -Belong [Now] =Taj; - Bcc[taj].push_back (now); the} while(Now! =u); the     } the } the  - voidTarjan_init (intAll ) { thememset (DFN,-1,sizeof(DFN)); thememset (Instack,0,sizeof(Instack)); thetop = time = Taj =0;94      for(intI=1; i<=all;i++)if(dfn[i]==-1) Tarjan (i, I);//Notice the start point!!!  the } thevector<int>G[n]; the intDu[n];98 voidSuodian () { AboutMemset (Du,0,sizeof(du)); -      for(inti =1; I <= Taj; i++) g[i].clear ();101      for(inti =0; i < Edgenum; i++){102         intU = belong[edge[i]. from], V =belong[edge[i].to];103         if(u!=v)104         { theG[u].push_back (v), du[v]++;106             //printf ("%d%d\n", u,v);107         }108     }109 } the voidInit () {memset (head,-1,sizeof(head)); edgenum=0;}111  the intMain ()113 { the    //Read (); the     intb; the      while(~SCANF ("%d%d", &n,&m) &&n+m)117     {118 init ();119          for(intI=0; i<m;i++) -         {121scanf"%d%d",&a,&b);122 Add (A, b);123         }124 tarjan_init (n); the         if(taj==1) puts ("Yes");126         ElsePuts"No");127         //Suodian (); -     }129     return 0; the}

hdu-1269 Maze Castle (strong connected nude)

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.