HDU 4240 Maximum flow path

Source: Internet
Author: User

Test instructions for half a day:

Give a direction graph, with edge right, SRC,DST. The maximum stream from src to DST is calculated, and the ratio of the traffic from SRC to the maximum DST flow is calculated.

1#include <cstdio>2#include <cstring>3#include <queue>4#include <vector>5 #defineOO 0x3f3f3f3f6 #defineMAXN 10107 using namespacestd;8 9 structEdge {Ten     intu, V, F, cap; OneEdge (intUintVintFintcap): U (U), V (v), F (f), Cap (CAP) {} A }; - structDinic { -     intN, SRC, DST; theVector<edge>Edge; -vector<int>G[MAXN]; -     intDEP[MAXN], CUR[MAXN], sig; -  +     voidInitintNintSrcintDST) { -          This->n =N; +          This-&GT;SRC =src; A          This-&GT;DST =DST; at          for(intu=1; u<=n; u++ ) - g[u].clear (); - edge.clear (); -     } -     voidAdd_edge (intUintVintf) { - G[u].push_back (Edge.size ()); in Edge.push_back (Edge (u,v,f,f)); - G[v].push_back (Edge.size ()); toEdge.push_back (Edge (V,u,0, F)); +     } -     BOOLBFs () { thequeue<int>Qu; *memset (DEP,0,sizeof(DEP)); $ Qu.push (SRC);Panax NotoginsengDEP[SRC] =1; -          while( !Qu.empty ()) { the             intu=Qu.front (); + Qu.pop (); A              for(intt=0; T<g[u].size (); t++ ) { theEdge &e =Edge[g[u][t]]; +                 if(E.F &&!)DEP[E.V]) { -DEP[E.V] = dep[e.u]+1; $ Qu.push (E.V); $                 } -             } -         } the         returnDEP[DST]; -     }Wuyi     intDfsintUintAintminc) { the         if(U==DST | | a==0 ) { -sig =Max (Minc, SIG); Wu             returnA; -         } About         intRemain=a, past=0, na; $          for(int&t=cur[u]; T<g[u].size (); t++ ) { -Edge &e =Edge[g[u][t]]; -Edge &ve = edge[g[u][t]^1]; -             if(dep[e.v]==dep[e.u]+1&& (na=Dfs (E.v,min (remain,e.f), Min (minc,e.cap)))) { ARemain-=na; +Past + =na; theE.F-=na; -Ve.f + =na; $                 if(remain==0) Break; the             } the         } the         returnpast; the     } -     voidMaxflow (int&tot,int&SIG) { inTot = sig =0; the          This->sig =0; the          while(BFS ()) { Aboutmemset (cur,0,sizeof(cur)); theTot + =DFS (src,oo,oo); the         } thesig = This-Sig; +     } - }; the Bayi intN, M; the dinic D; the intMain () { -     intT; -scanf"%d", &T); the      while(t-- ) { the         intcas, SRC, DST; thescanf"%d%d%d%d%d", &cas, &n, &m, &AMP;SRC, &DST); theSrc++, dst++; - d.init (n, SRC, DST); the          for(intI=1, U,v,w; i<=m; i++ ) { thescanf"%d%d%d", &u, &v, &W); theu++, v++;94 D.add_edge (U, V, W); the         } the         inttot, SIG; the D.maxflow (Tot, SIG);98printf"%d%.3lf\n"CasDouble(TOT)/Double(SIG)); About     } -}
View Code

HDU 4240 Maximum flow path

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.