hdu-1827 Summer Holiday (Strong connectivity)

Source: Internet
Author: User

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

After shrinking, the number of points that count to 0 is required to be notified, but these points may also be indented, so find a minimum value for each collection at this 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 1100 - //n is the maximum number of points the #defineM 2100 + //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 each strong connected component contains the points in the original -  - 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 intP[n]; the intMain ()113 { the     //Read (); the     intb; the      while(~SCANF ("%d%d",&n,&m))117     {118 init ();119          for(intI=1; i<=n;i++) scanf ("%d",&p[i]); -          for(intI=0; i<m;i++)121         {122scanf"%d%d",&a,&b);123 Add (A, b);124         } the tarjan_init (n);126 Suodian ();127         intx=0, ans=0, y; -          for(intI=1; i<=taj;++i)129         { they=1<< -;131             if(du[i]==0)//The number of degrees is 0 points the             {133X + +;134                  for(intj=0; J<bcc[i].size (); + +j)135y=min (y,p[bcc[i][j]]);136ans+=y;137             }138         }139         //printf ("%d\n", j); $printf"%d%d\n", X,ans);141     }142     return 0;143}

hdu-1827 Summer Holiday (Strong connectivity)

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.