Bzoj3130 [Sdoi2013] fee flow

Source: Internet
Author: User

Time Limit:10 Sec Memory limit:128 mbsec Special Judge
submit:1041 solved:536 Description

Alice and Bob learned about the maximum flow and minimum cost flow in the graph theory course.
Maximum flow problem: given a graph of the transport network, a source point S and a meeting point T, each edge has the maximum flow. A legitimate network flow scheme must satisfy: (1) The actual flow of each edge does not exceed its maximum flow and non-negative, (2) In addition to the source point S and the meeting point T, for all remaining points, the total inflow of the point is equal to the total outflow of the point, while the net outflow of S point is equal to T point net inflow This value is also the total traffic for this network flow scenario. The maximum flow problem is the network flow scheme with the largest traffic volume for a given transportation network.


Represents a maximum flow problem. For each edge, the number on the right represents the maximum flow for that edge, and the number on the left represents the actual flow of the edge in the optimal solution.    It is important to note that the solution to a maximum flow problem may not be unique. For a given transport network, Alice first determines a maximum stream, and if there are multiple solutions, Alice can choose one, and then Bob allocates units on each edge (the unit cost must be a nonnegative real number), requiring that all sides of the unit spend the sum equal to P. The total cost equals the actual traffic for each edge multiplied by the unit cost of the edge. It is important to note that Bob knows the maximum flow scheme that Alice has given before allocating units. Now Chigang Alice hopes the total cost is as small as possible, while Bob hopes the total cost is as large as possible. We want to know if two people are performing the optimal strategy, the value of the maximum stream and the total cost respectively.

Input

The first row of three integers n,m,p. n represents the number of nodes in a given transport network, m indicates the number of forward edges, and the meaning of P is described in the Problem Description section. To simplify the problem, we assume that the source point S is point 1 and that the meeting point T is point N.
The next m line, three integers per line a,b,c, indicates that there is a forward edge from point A to B, with a maximum flow of C.

Output

The first line is an integer that represents the value of the maximum stream.
The second line is a real number, which represents the total cost. It is recommended that players output more than four decimal places.

Sample Input3 2 1
1 2 10
2 3Sample Output10
10.0000
HINT

"Sample description"

For Alice, the scheme of the maximum flow is fixed. The actual traffic for two edges is 10.

For Bob, the first edge is assigned a 0.5 charge, and the second side is assigned a charge of 0.5. Total Cost

As: 10*0.5+10*0.5=10. It is possible to demonstrate that there is no greater allocation of total costs.

"Data size and conventions"

For 20% of the test data: all the forward edges of the maximum flow is 1.

For 100% of test data: N < = 100,m < = 1000.

For l00% test data: All points are numbered in I.. In the N range. 1 < = maximum Flow per edge

Volume < = 50000. 1 < = P < = 10. There is no edge in a given transport network with the same start and end points.

Network Flow + Two-point answer

Before brushing the two-week network flow, I feel that life experience has accumulated to a certain extent. For example, this problem can be seen at a glance is the maximum flow of two points to determine whether it is feasible.

(Bob is sure to pile up all the expenses on the side where the traffic is the biggest in order to make the most profit)

So confidently knocked two points on the answer up, confident to submit

However, WA dropped.

WTF why is the flow a real number?

Think carefully, although the title is not explicitly, but it is really a real number.

Kneeling in the language.

1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <queue>8 using namespacestd;9 Const Doubleeps=1e-6;Ten Const intinf=1e9; One Const intmxn= -; A intRead () { -     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} the      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; - } - structeg{ +     intx, y; -     DoubleF; +}eg[mxn*Ten]; A structedge{ at     intv,nxt; -     DoubleF; -}e[mxn* -]; - inthd[mxn],mct=1; - voidAdd_edge (intUintVDoublef) { -E[++MCT].V=V;E[MCT].NXT=HD[U];E[MCT].F=F;HD[U]=MCT;return; in } - voidInsertintUintVDoublec) { to Add_edge (u,v,c); +Add_edge (V,u,0); -     return; the } * voidinit () { $memset (HD,0,sizeofHD);Panax Notoginsengmct=1; - } the intn,m,s,t; + DoubleP; A intD[MXN]; the BOOLBFS () { +memset (D,0,sizeofd); -queue<int>Q; $d[s]=1; $ Q.push (S); -      while(!Q.empty ()) { -         intu=Q.front (); Q.pop (); the          for(intI=hd[u];i;i=e[i].nxt) { -             intv=e[i].v;Wuyi             if(!d[v] && e[i].f>EPS) { thed[v]=d[u]+1; - Q.push (v); Wu             } -         } About     } $     returnD[t]; - } - DoubleDFS (intUDoubleLim) { -     if(U==t | | fabs (LIM) <eps)returnLim; A     Doublef=0; +     Doubletmp; the      for(intI=hd[u];i;i=e[i].nxt) { -         intv=e[i].v; $         if(d[v]==d[u]+1&& e[i].f>EPS) { thetmp=DFS (V,min (LIM,E[I].F)); thee[i].f-=tmp; thee[i^1].f+=tmp; thelim-=tmp; -f+=tmp; in             if(lim<eps)returnF; the         } the     } Aboutd[u]=0; the     returnF; the } the DoubleDinic () { +     Doubleres=0; -      while(BFS ()) { the         Doubletmp=DFS (s,inf);Bayi         if(tmp<eps) Break; theres+=tmp; the     } -     returnRes; - } the voidBuild (DoubleLim) { the      for(intI=1; i<=m;i++){ the Insert (Eg[i].x,eg[i].y,min (Eg[i].f,lim)); the     } -     return; the } the Doubleans=0, Res; the voidsolve () {94 Build (INF); theres=dinic (); the     DoubleL=1, r=50000; the      while(ABS (R-L) >EPS) {98         DoubleMid= (L+R)/2; About init (); - Build (mid);101         if(Fabs (Dinic ()-res) <=EPS) {102ans=mid;103R=mid;104         } the         ElseL=mid;106     }107     return;108 }109 intMain () { thescanf"%D%D%LF",&n,&m,&P);111s=1; t=N; the     inti,j;113      for(i=1; i<=m;i++){ thescanf"%d%d", &eg[i].x,&eg[i].y); scanf ("%LF",&eg[i].f); the     } the solve ();117printf"%.0f\n", res);118printf"%.4f\n", p*ans);119     // -     return 0;121}

Bzoj3130 [Sdoi2013] fee flow

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.