Bzoj1834[zjoi2010]network network expansion "cost flow"

Source: Internet
Author: User

Description

Given a forward graph, each edge has a capacity of C and an expansion fee of W. The expansion fee here refers to the cost of expanding the capacity by 1.
Please:
1, in the case of no expansion, the maximum flow of 1 to N;
2, the maximum flow of 1 to N to increase the minimum required for the expansion of K cost.

Input

The first line contains three integer n,m,k, which represents the number of points, sides, and the amount of traffic required to the graph.
The next M-line contains four integer u,v,c,w, representing an edge from U to V with a capacity of C and a expansion fee of W.
n<=1000,m<=5000,k<=10

Output

The output file contains two integers in a row, representing the answers to question 1 and question 2, respectively.

Sample Input

5 8 2

1 2 5 8

2 5 9 9

5 1 6 2

5 1 1 8

1 2 8 7

2 5 4 9

1 2 1 1

1 4 2 1

Sample Output

13 19
*********************

Topic Analysis:

For the first question, the direct maximum flow

The second question can be based on the residual network of the first question.
For each side of the original u,v
Connect again a capacity of K, the cost for the side of the specified cost
And move the meeting point T back one , from the original t to the new T-edge capacity of K, the cost is 0
Running the cost stream can be
********************

#include <iostream> #include <algorithm> #include <cstdio> #include <queue> #include <    Cstring>using namespace Std;int read () {int x=0,f=1;    Char Ss=getchar (); while (ss< ' 0 ' | |    Ss> ' 9 ') {if (ss== '-') F=-1;ss=getchar ();}    while (ss>= ' 0 ' &&ss<= ' 9 ') {x=x*10+ss-' 0 '; Ss=getchar ();} return f*x;} const int Inf=1128481603;int n,m,k;int s=1,t;struct node{int v,f,c,nxt;} E[100010];int head[10010],tot=1;int dis[10010],vis[10010];int incf[1010],pre[10010];int from[10010],to[10010],cap[    10010],w[10010];int maxf,fee;void Add (int u,int v,int cap,int cost) {E[++tot].nxt=head[u];    E[tot].f=cap;    E[tot].c=cost;    E[tot].v=v; Head[u]=tot;}    BOOL BFs () {memset (dis,67,sizeof (dis)); dis[s]=0; Queue<int> Q; Q.push (s);        Incf[s]=inf;        while (!q.empty ()) {int U=q.front (); Q.pop ();        vis[u]=0;            for (int i=head[u];i;i=e[i].nxt) {int v=e[i].v;  if (E[I].F&AMP;&AMP;DIS[V]&GT;DIS[U]+E[I].C) {              DIS[V]=DIS[U]+E[I].C; Incf[v]=min (INCF[U],E[I].F);                Pre[v]=i;            if (!vis[v]) Q.push (v), vis[v]=1; }}} return dis[t]!=inf;}    void Dfs () {int u=t;        while (u!=s) {int i=pre[u]; E[I].F-=INCF[T];        E[I^1].F+=INCF[T];    U=E[I^1].V;    } Maxf+=incf[t]; FEE+=DIS[T]*INCF[T];}    int main () {n=read (); M=read (); K=read ();    T=n;        for (int i=1;i<=m;i++) {from[i]=read (); To[i]=read (); Cap[i]=read (); W[i]=read ();    Add (from[i],to[i],cap[i],0); add (to[i],from[i],0,0);    } while (BFS ()) Dfs ();        cout<<maxf<< ""; memset (head,0,sizeof (head));    Tot=1;        for (int i=1;i<=m;i++) {Add (from[i],to[i],cap[i],0); add (to[i],from[i],0,0);    Add (From[i],to[i],k,w[i]); Add (To[i],from[i],0,-w[i]);    } add (t,t+1,maxf+k,0); add (t+1,t,0,0); t++;    while (BFS ()) Dfs ();    cout<<fee; return 0;}

Bzoj1834[zjoi2010]network network capacity "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.