uva1486 Transportation
来源:互联网 发布:生辰八字高分起名软件 编辑:程序博客网 时间:2024/06/05 08:26
There are N cities, and M directed roads connecting them. Now you
want to transport K units of goods from city 1 to city N . There are
many robbers on the road, so you must be very careful. The more goods
you carry, the more dangerous it is. To be more specific, for each
road i , there is a coefficient a i . If you want to carry x units of
goods along this road, you should pay a i x 2 dollars to hire guards
to protect your goods. And what’s worse, for each road i , there is an
upper bound C i , which means that you cannot transport more than C i
units of goods along this road. Please note you can only carry
integral unit of goods along each road. You should find out the
minimum cost to transport all the goods safely. Input There are
several test cases. The first line of each case contains three
integers, N , M and K . ( 1 N 100 , 1 M 5000 , 0 K 100 ).
Then M lines followed, each contains four integers ( u i ; v i ; a i ;
C i ) , indicating there is a directed road from city u i to v i ,
whose coefficient is a i and upper bound is C i . ( 1 u i ; v i N
, 0 < a i 100 , C i 5 ) Output Output one line for each test case,
indicating the minimum cost. If it is impossible to transport all the
K units of goods, output ‘
-1 ’
因为
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int s=105,t=106,oo=0x3f3f3f3f,mod=107;int fir[110],ne[200010],to[200010],w[200010],c[200010],que[110],in[110],minw[110],len[110],fa[110],n,m,k,num;void add(int u,int v,int x,int y){ num++; ne[num*2]=fir[u]; fir[u]=num*2; to[num*2]=v; w[num*2]=x; c[num*2]=y; ne[num*2+1]=fir[v]; fir[v]=num*2+1; to[num*2+1]=u; w[num*2+1]=0; c[num*2+1]=-y;}void init(){ int u,v,a,c; memset(fir,0,sizeof(fir)); num=0; while (m--) { scanf("%d%d%d%d",&u,&v,&a,&c); for (int i=1;i<=c;i++) add(u,v,1,a*i*i-a*(i-1)*(i-1)); } add(s,1,k,0); add(n,t,k,0);}void solve(){ int u,v,hd,tl,ans=0; while (1) { hd=0,tl=1; in[s]=1; que[0]=s; memset(minw,0,sizeof(minw)); minw[s]=oo; memset(len,0x3f,sizeof(len)); len[s]=0; while (hd!=tl) { u=que[hd++]; hd%=mod; for (int i=fir[u];i;i=ne[i]) if (w[i]&&len[v=to[i]]>len[u]+c[i]) { len[v]=len[u]+c[i]; minw[v]=min(minw[u],w[i]); fa[v]=i; if (!in[v]) { in[v]=1; que[tl++]=v; tl%=mod; } } in[u]=0; } if (!minw[t]) break; for (int i=fa[t];i;i=fa[to[i^1]]) { w[i]-=minw[t]; w[i^1]+=minw[t]; } ans+=minw[t]*len[t]; } if (w[fir[s]]) printf("-1\n"); else printf("%d\n",ans);}int main(){ while (scanf("%d%d%d",&n,&m,&k)==3) { init(); solve(); }}
- uva1486 Transportation
- 【费用流模型】BZOJ2668 UVA1317 UVA1486 UVA1104
- 【费用流模型】BZOJ2668 UVA1317 UVA1486 UVA1104
- 301Transportation(****)
- <poj1040>Transportation
- 301 - Transportation
- UVA301- Transportation
- uva301 - Transportation
- UVaOJ301 - Transportation
- POJ1040 Transportation
- UVA301- Transportation
- uva301 - Transportation
- [toj1003]Transportation
- Intelligent Transportation
- HDU3667.Transportation
- Transportation poj1040
- Heavy Transportation
- Heavy Transportation
- 升降序排列
- 在2017年,如何将你的小米4刷上Windows 10 mobile?(后附大量图赏)
- Java中ByteBuffer
- codeforce118A String Task
- 常用的时间工具类
- uva1486 Transportation
- CentoOS7 上安装MySQL 5.7
- 洛谷 P1005 矩阵取数游戏
- 【Unity】中如何通过GPS获取设备经纬度(测试脚本)
- mysql数据库数字格式化和日期时间格式化
- JS 倒计时
- Allegro中如何导入DXF文件
- QT中*.pro文件的写法介绍
- AS 下载/安装/简单使用/创建模拟器