HDU 2242 Entrance Examination Road boundless-air-conditioning classroom (double connected entry)

Source: Internet
Author: User

1 /**********************************************************2 Title: Entrance Examination Road boundless--air-conditioning classroom (HDU 2242)3 Links:http://acm.hdu.edu.cn/showproblem.php?pid=22424 algorithm: Double unicom5 idea: Find the bridge and then calculate the difference on both sides of the bridge, on the side of the bridge6 the value is compressed to the number adjacent to the other side. 7 8 ***********************************************************/9 Ten#include <cstdio> One#include <iostream> A#include <cstring> -#include <algorithm> -#include <vector> the#include <stack> - using namespacestd; -  - Const intmx=100005; + intA[MX]; -stack<int>s; +vector<int>G[MX]; A intFlag,dfs_cut; at intDFN[MX],LOW[MX],VS[MX]; - intans,sum; -  - voidInit (intN) - { -     inti; insum=0; -      for(i=0; i<n;i++) to     { + g[i].clear (); -scanf"%d",&a[i]); thesum+=A[i]; *     } $memset (DFN,0,sizeof(DFN));Panax Notoginsengmemset (Low,0,sizeof(Low)); -Memset (VS,0,sizeof(VS)); theflag=dfs_cut=0; +ans=sum; A } the  + voidDfsintUintFA) - { $dfn[u]=low[u]=++Dfs_cut; $vs[u]=1; - s.push (u); -     intp=1;///Go heavy the      for(intI=0; I<g[u].size (); i++) -     {Wuyi  the         intv=G[u][i]; -         if(v==fa&&p) Wu         { -p=0; About             Continue; $         } -         if(!Vs[v]) -         { - DFS (v,u); Alow[u]=min (low[u],low[v]); +             if(Low[v]>dfn[u])///judging the bridge the             { -flag=1; $                 inttemp=0, X; the                  the                 ///to compress the bridge once again the                  while(1) the                 { -x=s.top (); in S.pop (); thetemp+=A[x]; the                     if(X==V) Break; About                 } theAns=min (Ans,abs (sum-2*temp)); thea[u]+=temp; the             } +  -         } the         Elselow[u]=min (low[u],dfn[v]);Bayi     } the } the  - intMain () - { the     intn,m; the      while(~SCANF ("%d%d",&n,&m)) the     { the Init (n); -          while(m--) the         { the             intu,v; thescanf"%d%d",&u,&v);94 G[u].push_back (v); the g[v].push_back (u); the         } theDfs0,-1);98         if(flag) printf ("%d\n", ans); About         Elseprintf"impossible\n"); -     }101}

HDU 2242 Entrance Examination Road boundless-air-conditioning classroom (double connected entry)

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.