不管怎么说,模板才是最重要的!!!
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 1005
#define nm 40005
#define pi 3.1415926535897931
using namespace std;
const ll inf=100000000000000005;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
struct edge{int t;ll v,w;edge*next,*rev;}e[nm],*h[NM],*o=e,*p[NM];
void _add(int x,int y,int w,int v){o->t=y;o->v=v;o->w=w;o->next=h[x];h[x]=o++;}
void add(int x,int y,int w,int v){_add(x,y,w,v);_add(y,x,0,-v);h[x]->rev=h[y];h[y]->rev=h[x];}
int n,m,_x,_y,_t,_w;
ll ans,s,d[NM],w[NM];
bool v[NM];
queue<int>q;
int spfa(){
mem(d);mem(v);mem(w);mem(p);
inc(i,1,n)d[i]=inf;
d[1]=0;v[1]++;w[1]=inf;q.push(1);
while(!q.empty()){
int t=q.front();q.pop();v[t]=false;
link(t)if(j->w&&d[j->t]>d[t]+j->v){
d[j->t]=d[t]+j->v;w[j->t]=min(w[t],j->w);p[j->t]=j;
if(!v[j->t])v[j->t]++,q.push(j->t);
}
}
return w[n];
}
int main(){
n=read();m=read();
inc(i,1,m){_x=read();_y=read();_w=read();_t=read();add(_x,_y,_w,_t);}
while(spfa()){
ans+=w[n];s+=w[n]*d[n];
for(int x=n;p[x];x=p[x]->rev->t)p[x]->w-=w[n],p[x]->rev->w+=w[n];
}
return 0*printf("%lld %lld\n",ans,s);
}
#102. 最小费用流
内存限制:256 MiB
时间限制:4000 ms
标准输入输出
题目类型:传统
评测方式:文本比较
上传者: 匿名