hdu 3667 Transportation 费用流
来源:互联网 发布:淘宝欧米茄翻新表 编辑:程序博客网 时间:2024/06/05 10:53
很明显的费用流的题目,把一条边拆成5条即可。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=1e2+9;int n,m,p;int head[maxn],lon;struct{ int next,to,c,w,from;}e[222222];void edgeini(){ memset(head,-1,sizeof(head)); lon=-1;}void edgemake(int from,int to,int c,int w){ e[++lon].to=to; e[lon].from=from; e[lon].c=c; e[lon].w=w; e[lon].next=head[from]; head[from]=lon;}void make(int from,int to,int c,int w){ edgemake(from,to,c,w); edgemake(to,from,0,-w);}bool inque[maxn];int dist[maxn],from[maxn];int que[1111111];bool spfa(int s,int t){ memset(dist,50,sizeof(dist)); int front=1,end=0; que[++end]=s; inque[s]=1; dist[s]=0; while(front<=end) { int u=que[front++]; inque[u]=0; for(int k=head[u];k!=-1;k=e[k].next) { int v=e[k].to; if(e[k].c==0) continue; if(dist[v]>dist[u]+e[k].w) { dist[v]=dist[u]+e[k].w; from[v]=k; if(!inque[v]) { inque[v]=1; que[++end]=v; } } } } return dist[t]<100000000;}int mincostflow(int s,int t){ int ret=0; while(spfa(s,t)&&(p--)) { int u=t; while(u!=s) { int k=from[u]; e[k].c--; e[k^1].c++; ret+=e[k].w; u=e[k].from; } } if(p<=0) return ret; else return -1;}int main(){// freopen("in.txt","r",stdin); while(scanf("%d%d%d",&n,&m,&p)!=EOF) { edgeini(); for(int i=1,from,to,w,c;i<=m;i++) { scanf("%d%d%d%d",&from,&to,&w,&c); for(int j=1;j<=c;j++) { make(from,to,1,w*(2*j-1)); } } int ans=mincostflow(1,n); cout<<ans<<endl; } return 0;}
- hdu 3667 Transportation 费用流
- hdu 3667 Transportation 费用流
- HDU 3667 Transportation 费用流
- hdu 3667 Transportation 费用流
- hdu 3667 Transportation //拆边费用流
- HDU 3667 Transportation 费用流(拆边)
- HDU 3667 Transportation (最小费用最大流)
- hdu 3667 Transportation(拆边费用流)
- HDU 3667 Transportation | 费用流(拆边)
- HDU 3667 Transportation(最小费用最大流)
- HDU 3667 — Transportation 费用流
- hdu 3667 Transportation【费用流 + 拆边】
- hdu 3667 Transportation 费用流+拆边
- HDU 3667 Transportation(最小费用最大流)
- hdu 3667 Transportation【最小费用流+拆边】
- HDU 3667 Transportation(网络流之费用流)
- 网络流 (费用流+拆边)——Transportation ( HDU 3667 )
- hdu 3667 Transportation(最小费用流+拆边)
- Vxworks下flash驱动编写流程 .
- 神马是敏捷?(1)——敏捷的“官方”定义
- package of python
- hadoop之hive在数据检索中的用法
- 单链表的主要一些算法
- hdu 3667 Transportation 费用流
- RH436之iSCSI 配置
- 第一次开博,纪念我那逝去的青春!
- SSDT索引号的获取
- Cocos2d-x教程(8)-遮罩层实现捕鱼达人滚动数字表盘
- (转)楼教主回忆录
- Working Practice-可以检查系统的三种方式
- Java面向对象【经典案例】构造器
- Android中Paint字体的使用