HDU4240 Route Redundancy
来源:互联网 发布:c语言入门之后学什么 编辑:程序博客网 时间:2024/06/06 00:27
HDU4240 Route Redundancy
Background
A city is made up exclusively of one-way steets.each street in the city has a capacity,which is the minimum of the capcities of the streets along that route.
The redundancy ratio from point A to point B is the ratio of the maximum number of cars that can get from point A to point B in an hour using all routes simultaneously,to the maximum number of cars thar can get from point A to point B in an hour using one route.The minimum redundancy ratio is the number of capacity of the single route with the laegest capacity.
Input
The first line of input contains asingle integer P,(1<=P<=1000),which is the number of data sets that follow.Each data set consists of several lines and represents a directed graph with positive integer weights.
The first line of each data set contains five apace separatde integers.The first integer,D is the data set number. The second integer,N(2<=N<=1000),is the number of nodes inthe graph. The thied integer,E,(E>=1),is the number of edges in the graph. The fourth integer,A,(0<=A
#include <cstdio>#include <cstdlib>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#define Inf 0x7fffffffusing namespace std;int P,D,n,m,st,ed;int len;struct node{ int w,next,v;}t[1000010];int temp[1000010];int head[1010],Maxd,pre[1010],dis[1010],gap[1010],cur[1010];void add(int x,int y,int w){ t[len].v=y; t[len].next=head[x]; t[len].w=w; temp[len]=w; head[x]=len++;}int Isap(){ int flow=0,d=Inf,i,u; for (i=0; i<=n; i++) { cur[i]=head[i]; dis[i]=gap[i]=0; } gap[0]=n; u=pre[st]=st; int flag; while (dis[u]<n) { flag=0; for (int &j=cur[u]; j!=-1; j=t[j].next) { //printf("%d\n",u); int v=t[j].v; if (t[j].w>0&&dis[v]+1==dis[u]) { flag=true; d=min(d,t[j].w); pre[v]=u; u=v; if (u==ed) { flow+=d; int Mind=Inf; bool mark=true; while (u!=st) { u=pre[u]; if (temp[cur[u]]==0) mark=false; Mind=min(temp[cur[u]],Mind); t[cur[u]].w-=d; t[cur[u]^1].w+=d; } //printf("%d\n",Mind); if(mark) Maxd=max(Mind,Maxd); d=Inf; } break; } } if (flag) continue; int minh=n; for (int j=head[u]; j!=-1; j=t[j].next) { int v=t[j].v; if (t[j].w>0 && dis[v]<minh) { minh=dis[v]; cur[u]=j; } } if ((--gap[dis[u]])==0) break; dis[u]=minh+1; gap[dis[u]]++; u=pre[u]; } return flow;}int main(){ freopen("1.in","r",stdin); int i,j,a,b,w; scanf("%d",&P); while (P--) { memset(head,-1,sizeof(head)); scanf("%d",&D); scanf("%d%d%d%d",&n,&m,&st,&ed); len=0; for (i=0; i<m; i++) { scanf("%d%d%d",&a,&b,&w); add(a,b,w); add(b,a,0); //printf("%d %d %d\n",a,b,w); } Maxd=-1; double ans=1.0*Isap(); //printf("%d \n",Maxd); ans=ans/Maxd; printf("%d %.3lf\n",D,ans); } return 0;}
- HDU4240 Route Redundancy
- 【网络流】 HDU4240 Route Redundancy 基础
- HDU 4240 Route Redundancy
- HDU 4240 Route Redundancy
- hdu 4240 Route Redundancy(dinic)
- [最大流] hdu 4240 Route Redundancy
- hdu 4240 Route Redundancy(最大流)
- hdu 4240 Route Redundancy(最大流)
- hdu 4240 Route Redundancy 网络流
- hdu 4240 Route Redundancy 最大流 isap
- HDU 4240 Route Redundancy【最大流】
- hdoj 4240 Route Redundancy 【最大流+ SPFA】
- HDU 4240 Route Redundancy 网络流
- 【 hdoj 4240】 Route Redundancy 【dinic+spfa】
- Redundancy
- HDOJ 4240 - Route Redundancy 最大流+DP...阅读理解...
- HDU 4240 Route Redundancy 一条流最大的路径
- HDU — 4240 Route Redundancy(最大流)
- 一个面试题
- 命令
- iphone开发内存管理──静态全局变量的内存问题
- 自己写一个Json解析的模型
- 搭建SpringMVC+Hibernate4+Spring3+Ajax+Maven项目
- HDU4240 Route Redundancy
- 介绍一种在Xcode中删除一整行代码的快捷键设置,
- dns ttl
- Armadillo C++ linear algebra library 学习笔记(7)——统计相关函数
- groupadd命令详解(实例)
- Windows的线程管理和调度机制
- 简单的MD5查询工具
- U-Boot添加命令的方法
- MySQL常见查询语句