HDU 4240 Route Redundancy(基础) [最大流]一条流最大的路径
来源:互联网 发布:数据的分散程度怎么求 编辑:程序博客网 时间:2024/05/16 12:09
题意:依旧是那么难读懂,在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Maxflow)/所有边上通过最大车流量(cap)的那条叫做redundancy ratio。最小的redundancy ratio是前者最大的车流量的那一条(cap),问minimum redundancy ratio是多少。
思路:最大流不用说,分母是在找最大流的时候记录下最大的cap
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))const int maxn=20006;const int inf=1<<28;const int nv=1100;const int ne=501000;int mxCap;struct isap{ int n,size; int head[nv]; int dis[nv],gap[nv],cur[nv],pre[nv]; int maxflow; struct edge{ int v,w,next; edge(){} edge(int _v,int _w,int _next):v(_v),w(_w),next(_next){} }E[ne]; void init(){ //需要在外面额外设置n的大小 size=0; //for(int i=0;i<=n;i++)head[i]=-1; cl(head,-1); } void insert(int u,int v,int w){ E[size]=edge(v,w,head[u]); head[u]=size++; E[size]=edge(u,0,head[v]); head[v]=size++; } int maxFlow(int src,int des){ maxflow=0; for(int i=0;i<=n;i++){ dis[i]=gap[i]=0; cur[i]=head[i]; } int u=pre[src]=src; int aug=0;///or aug=-1 while(dis[src]<n){ loop:for(int &i=cur[u];i!=-1;i=E[i].next){ int v=E[i].v; if(E[i].w&&dis[u]==dis[v]+1){ aug=min(aug,E[i].w); pre[v]=u; u=v; if(v==des){ maxflow+=aug; mxCap=max(mxCap,aug);//成功找到一条增广路,记录下这个最大值 for(u=pre[u];v!=src;v=u,u=pre[u]){ E[cur[u]].w-=aug; E[cur[u]^1].w+=aug; } aug=inf; } goto loop; } } int mdis=n; for(int i=head[u];i!=-1;i=E[i].next){ int v=E[i].v; if(E[i].w&&mdis>dis[v]){ cur[u]=i; mdis=dis[v]; } } if(--gap[dis[u]]==0)break; gap[dis[u]=mdis+1]++; u=pre[u]; } return maxflow; }}G;int main(){ int cas=1; int T; scanf("%d",&T); while(T--){ int n,m,s,t,d; scanf("%d%d%d%d%d",&d,&n,&m,&s,&t); G.init(); G.n=n; mxCap=0; while(m--){ int u,v,w; scanf("%d%d%d",&u,&v,&w); G.insert(u,v,w); } int tmp=G.maxFlow(s,t); //printf("flow = %d, maxcap = %d\n",tmp,mxCap); printf("%d %.3lf\n",d,tmp*1.0/mxCap); } return 0;}
0 0
- HDU 4240 Route Redundancy 一条流最大的路径
- 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【最大流】
- HDU — 4240 Route Redundancy(最大流)
- HDU 4240 --Route Redundancy【最大流dinic && DFS】
- hdoj 4240 Route Redundancy 【最大流+ SPFA】
- hdu 4240 Route Redundancy(求起点到终点的路径中流量最大的路径的流量)
- HDOJ 4240 - Route Redundancy 最大流+DP...阅读理解...
- hdu 4240 Route Redundancy 网络流
- HDU 4240 Route Redundancy 网络流
- HDU 4240 Route Redundancy
- HDU 4240 Route Redundancy
- HDU4240Route Redundancy(最大流SAP)
- 【网络流】 HDU4240 Route Redundancy 基础
- java读取html文件并抽取a href相关连接和链接标题
- android 播放gif
- java 删除指定文件夹 以及文件下下面的所有文件
- VS2015 windows 编译WebKit 代码
- 四、Android.mk之编译生成可执行文件
- HDU 4240 Route Redundancy(基础) [最大流]一条流最大的路径
- 【Matlab学习笔记】【函数学习】cat函数
- 认证Xcode版本
- sqlparameter参数查询,防注入攻击
- iOS UIAppearance最全详解
- 深入理解Java的接口和抽象类
- CAD控件:在安卓,苹果手机当中浏览和编辑DWG
- connect()链接不成功问题总结
- java的String类StringBuffer类StringBuilder类