Codeforces 708D Upper and lower boundary cost flow

Source: Internet
Author: User

Give you a picture of a network flow may have traffic imbalance and traffic > capacity conditions exist

One unit of cost per unit of traffic/capacity to be adjusted

Ask at least how much it takes to make the original image adjust to the correct (feasible) network flow

Set the current edge information to (U,V,F,C) that is, from u to v there is a flow of f, the capacity of C has a forward edge

The added edge information is [u,v,f,c] that is, add a bar from U to V with a capacity of F, the unit cost of C of the forward side

First, if the Yuanhui flow is unbalanced, add an edge [t,s,inf,0] to make the Yuanhui flow balance

The following is a discussion of the situation:

①: Flow f> capacity C

First of all, the ans+=f-c must be adjusted F-C units to make the edge legal

Add Edge [u,v,inf,2] This edge means to raise F for f=c when it takes 2 of the cost (need to increase C at the same time)

Added edge [v,u,f-c,0] can be used to reduce flow

Added edge [v,u,c,1] can be used to reduce flow

Side [u,v,inf,2] very good understanding but how to understand the side [v,u,f-c,0] and [v,u,c,1]

First we analyze the flow of the side F after the adjustment has the following conditions 1.   [0,c] 2.[C,F] 3. [F,inf]

The first case C does not need to be adjusted is f because we pay the F-C fee upfront so the f~c phase cost is 0 and the 0~c phase unit Cost is 1

The second case C and F need to be adjusted at the same time but the total cost is f-c we just need to use [v,u,f-c,0] to adjust to the desired F

Third-party conditions C and F also need to be adjusted but F does not decrease, so the next two kinds of edges are void.

So these three kinds of edges can include all the conditions of F.

②: Flow f<= capacity C

Add Edge [u,v,inf,2] this edge means to increase the cost of a unit F when F=c is 2 (need to increase C at the same time)

Add edge [u,v,f-c,1] f~c this unit costs 1

Add edge [v,u,f,1] 0~f this unit costs 1

After adding the side of the expense flow for each (U,V,F,C) needflow[u]-=f needflow[v]+=f

For each point (including Yuanhui)

needflow[i]>0 add [ss,i,needflow[i],0] needflow[i]<0 add [i,tt,-needflow[i],0]

Last run once the minimum cost stream of SS to TT plus the previous ANS is the answer

Codeforces 708D Upper and lower boundary cost 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.