【网络流】 HDU4240 Route Redundancy 基础
来源:互联网 发布:Linux持续ping命令 编辑:程序博客网 时间:2024/06/05 20:52
求the minimum redundancy ratio
the minimum redundancy ratio=maxflow/flow
flow为最大流中最大的一条增光路
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <cmath>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#include <set>#include <map>#include <time.h>;#define cler(arr, val) memset(arr, val, sizeof(arr))#define FOR(i,a,b) for(int i=a;i<=b;i++)#define IN freopen ("in.txt" , "r" , stdin);#define OUT freopen ("out.txt" , "w" , stdout);typedef long long LL;const int MAXN = 1004;const int MAXM = 4100;const int INF = 0x3f3f3f3f;const int mod = 1000000007;struct Edge{ int to,next,cap,flow;}edge[MAXM];//注意是MAXMint tol;int head[MAXN];int gap[MAXN],dep[MAXN],cur[MAXN];void init(){ tol = 0; memset(head,-1,sizeof (head));}void addedge (int u,int v,int w,int rw = 0){ edge[tol].to = v; edge[tol].cap = w; edge[tol].flow = 0; edge[tol].next = head[u]; head[u] = tol++; edge[tol].to = u; edge[tol].cap = rw; edge[tol].flow = 0; edge[tol].next = head[v]; head[v] = tol++;}int Q[MAXN];void BFS(int start,int end){ memset(dep,-1,sizeof(dep)); memset(gap,0,sizeof(gap)); gap[0] = 1; int front = 0, rear = 0; dep[end] = 0; Q[rear++] = end; while(front != rear) { int u = Q[front++]; for(int i = head[u]; i != -1; i = edge[i].next) { int v = edge[i]. to; if(dep[v] != -1)continue; Q[rear++] = v; dep[v] = dep[u] + 1; gap[dep[v]]++; } }}int S[MAXN],out;int sap(int start,int end, int N){ BFS(start,end); memcpy(cur,head,sizeof(head)); int top = 0; int u = start; int ans = 0; int i; while(dep[start] < N) { if(u == end) { int Min = INF; int inser; for( i = 0;i < top;i++) { if(Min > edge[S[i]].cap - edge[S[i]].flow) { Min = edge[S[i]].cap - edge[S[i]].flow; inser = i; } } for( i = 0;i < top;i++) { edge[S[i]]. flow += Min; edge[S[i]^1].flow -= Min; } ans += Min; out=max(Min,out); top = inser; u = edge[S[top]^1].to; continue; } bool flag = false; int v; for( i = cur[u]; i != -1; i = edge[i]. next) { v = edge[i]. to; if(edge[i].cap - edge[i].flow && dep[v]+1 == dep[u]) { flag = true; cur[u] = i; break; } } if(flag) { S[top++] = cur[u]; u = v; continue; } int Min = N; for( i = head[u]; i != -1; i = edge[i].next) { if(edge[i].cap - edge[i].flow && dep[edge[i].to] < Min) { Min = dep[edge[i].to]; cur[u] = i; } } gap[dep[u]]--; if(!gap[dep[u]]) return ans; dep[u] = Min + 1; gap[dep[u]]++; if(u != start)u = edge[S[--top]^1].to; } return ans;}int main(){ int t; // IN; scanf("%d",&t); while(t--) { init(); int u,v,c; int a,b,d,n,m; out=0; scanf("%d%d%d%d%d",&d,&n,&m,&a,&b); for(int i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&c); addedge(u,v,c); } int ans=sap(a,b,n); printf("%d %.3lf\n",d,ans*1.0/out); } return 0;}
0 0
- 【网络流】 HDU4240 Route Redundancy 基础
- HDU4240 Route Redundancy
- 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【最大流】
- hdoj 4240 Route Redundancy 【最大流+ SPFA】
- HDU 4240 Route Redundancy(基础) [最大流]一条流最大的路径
- HDU 4240 Route Redundancy
- HDU 4240 Route Redundancy
- HDOJ 4240 - Route Redundancy 最大流+DP...阅读理解...
- HDU 4240 Route Redundancy 一条流最大的路径
- HDU — 4240 Route Redundancy(最大流)
- HDU 4240 --Route Redundancy【最大流dinic && DFS】
- hdu 4240 Route Redundancy(dinic)
- UISegmentedControl UISlider
- 自传 第一章 永别 告别式 (二)
- 易宝抢滩第二波:发力中后台流程改造
- 苹果Mac10.9下Qt 5.3.2的安装、配置(1)
- 内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区[C++][内存管理]
- 【网络流】 HDU4240 Route Redundancy 基础
- equals ==
- 【iOS开发-27】解决方案:An error was encountered while running(Domain=FBSOpenApplicationErrorDomain, Code=4)
- BLAS/LAPACK 函数/子程序命名规则
- 拉格朗日插值
- 索引的几种访问方法
- 杭电oj find your present (2)
- HDFS概述
- 在VC中调用WORD(显示,修改,存盘,运行宏)