bzoj1834
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.
First by the cost of 0, the capacity of the C run cost flow for the maximum flow, and then to each edge of the original image to build a capacity inf, the cost of W, new super Source and 1 edge, capacity K, cost 0,
Because to ensure that traffic increases k, and the original image of the edge is no cost, and as long as the increase in costs, traffic must be enough, so set to INF
/************************************************************** problem:1834 user:walfy language:c++ Result : Accepted time:112 ms memory:2720 kb****************************************************************///#pragma com MENT (linker, "/stack:200000000")//#pragma gcc optimize ("ofast,no-stack-protector")//#pragma gcc target ("Sse,sse2, Sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ")//#pragma GCC optimize (" Unroll-loops ") #include <bits/stdc++.h > #define FI first#define se second#define mp make_pair#define pb push_back#define Pi ACOs ( -1.0) #define LL Long Long#def INE VI vector<int> #define MOD 1000000007#define ld long double#define C 0.5772156649#define ls l,m,rt<<1#defi Ne rs m+1,r,rt<<1|1#define pil pair<int,ll> #define PLI pair<ll,int> #define PII pair<int,int># Define CD complex<double> #define ULL unsigned long long#define base 1000000000000000000#define Fio ios::sync_with_ Stdio (false); Cin.tie (0) using namespace std; Const Double Eps=1e-6;const int n=20000+10,maxn=50000+10,inf=0x3f3f3f3f,inf=0x3f3f3f3f3f3f3f3f; struct edge{int to,next,c; int cost;} E[maxn];int cnt,head[n];int s,t;int dis[n],pre[n],path[n];bool vis[n];void Add (int u,int v,int c,int cost) {E[cnt].to=v ; E[cnt].c=c; E[cnt].cost=cost; E[CNT]. Next=head[u]; head[u]=cnt++; E[cnt].to=u; e[cnt].c=0; E[cnt].cost=-cost; E[CNT]. NEXT=HEAD[V]; head[v]=cnt++;} BOOL Spfa () {memset (pre,-1,sizeof pre); memset (dis,inf,sizeof dis); memset (vis,0,sizeof Vis); dis[s]=0; Vis[s]=1; queue<int>q; Q.push (s); while (!q.empty ()) {int X=q.front (); Q.pop (); vis[x]=0; for (int i=head[x];~i;i=e[i]. Next) {int te=e[i].to; if (E[i].c>0&&dis[x]+e[i].cost<dis[te]) {dis[te]=dis[x]+e[i].cost; Pre[te]=x; Path[te]=i; if (!vis[te]) Q.push (TE), vis[te]=1; } }} return pre[t]!=-1;} int Maxflow () {int flow=0; while (SPFA ()) {int f=inf; for (int i=t;i!=s;i=pre[i]) if (e[path[i]].c<f) f=e[path[i]].c; Flow+=f; for (int i=t;i!=s;i=pre[i]) {e[path[i]].c-=f; E[path[i]^1].c+=f; }} return flow;} int Mincostmaxflow () {int cost=0,flow=0; while (SPFA ()) {int f=inf; for (int i=t;i!=s;i=pre[i]) if (e[path[i]].c<f) f=e[path[i]].c; Flow+=f; Cost+=dis[t]*f; for (int i=t;i!=s;i=pre[i]) {e[path[i]].c-=f; E[path[i]^1].c+=f; }} return cost; void Init () {memset (head,-1,sizeof head); cnt=0;} struct Node{int u,v,c,w;} Te[n];int Main () {int n,m,k; scanf ("%d%d%d", &n,&m,&k); Init (); for (int i=0;i<m;i++) {int u,v,c,w; scanf ("%d%d%d%d", &u,&v,&c,&w); Add (u,v,c,0); Te[i]={u,v,c,W}; } s=1,t=n; printf ("%d", Maxflow ()); for (int i=0;i<m;i++) Add (TE[I].U,TE[I].V,INF,TE[I].W); S=n+1;add (s,1,k,0); printf ("%d\n", Mincostmaxflow ()); return 0;} /******************** ********************/
bzoj1834: [zjoi2010]network Network expansion fee flow