hdu 4240 Route Redundancy 最大流
2015-03-09 23:33
295 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240
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.
题目描述:The redundancy ratio定义为:(A到B所有路径的流的和)/(A到B一条路径的流的值),求最小的The redundancy ratio(即A到B一条路径上的权值最大)。
算法分析:最大流的求解过程中更新每一条增广路的流的大小即可。
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.
题目描述:The redundancy ratio定义为:(A到B所有路径的流的和)/(A到B一条路径的流的值),求最小的The redundancy ratio(即A到B一条路径上的权值最大)。
算法分析:最大流的求解过程中更新每一条增广路的流的大小即可。
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<vector> #include<queue> #define inf 0x7fffffff using namespace std; const int maxn=1000+10; const int M = 9999999; int n,m,A,B; int from,to; int d[maxn]; int one; struct node { int v,flow; int next; }edge[M]; int head[maxn],edgenum; void add(int u,int v,int flow) { edge[edgenum].v=v ;edge[edgenum].flow=flow; edge[edgenum].next=head[u]; head[u]=edgenum++; edge[edgenum].v=u ;edge[edgenum].flow=0; edge[edgenum].next=head[v]; head[v]=edgenum++; } int bfs() { memset(d,0,sizeof(d)); d[from]=1; queue<int> Q; Q.push(from); while (!Q.empty()) { int u=Q.front() ;Q.pop() ; for (int i=head[u] ;i!=-1 ;i=edge[i].next) { int v=edge[i].v; if (!d[v] && edge[i].flow>0) { d[v]=d[u]+1; Q.push(v); if (v==to) return 1; } } } return 0; } int dfs(int u,int flow) { if (u==to || flow==0) { if (u==to) one=max(one,flow); return flow; } int cap=flow; for (int i=head[u] ;i!=-1 ;i=edge[i].next) { int v=edge[i].v; if (d[v]==d[u]+1 && edge[i].flow>0) { int x=dfs(v,min(cap,edge[i].flow)); edge[i].flow -= x; edge[i^1].flow += x; cap -= x; if (cap==0) return flow; } } return flow-cap; } double dinic() { double sum=0; one=0; while (bfs()) sum += (double)dfs(from,inf); cout<<sum<<" "<<one<<endl; return sum/(double)one; } int main() { int t,D; scanf("%d",&t); while (t--) { scanf("%d%d%d%d%d",&D,&n,&m,&A,&B); memset(head,-1,sizeof(head)); edgenum=0; from=A; to=B; int a,b,c; for (int i=0 ;i<m ;i++) { scanf("%d%d%d",&a,&b,&c); add(a,b,c); } double ans=dinic(); printf("%d %.3lf\n",D,ans); } return 0; }
相关文章推荐
- hdu 4240在(最大流)
- HDU 4240 Route Redundancy 一条流最大的路径
- [最大流] hdu 4240 Route Redundancy
- hdu 4240在(最大流)
- HDU 4240 --Route Redundancy【最大流dinic && DFS】
- 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(最大流+最大流量的路)
- hdu 4240 Route Redundancy(最大流)
- hdu 4240 最大流量路径
- hdu 4240 最大流dicnic
- HDU_4240_Route Redundancy(最大流dinic or EK)
- hdu 2768 Cat vs. Dog 最大独立集
- hdu 3415 Max Sum of Max-K-sub-sequence 单调队列 求连续l(1<=l<=k)个数的和的最大值 数列可循环
- HDU 3491 Thieves 【拆点+最大流】
- HDU 1042 求N的阶层,N的取值最大为10000