HDU 4240 Route Redundancy
Route Redundancy
This problem will be judged on HDU. Original ID: 4240
64-bit integer IO format: %I64d Java class name: Main
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 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<N),is the index of point A.The fifth integer,B,(o<=B<N,A!=B),is the index of point B.
The remaining E lines desceibe each edge. Each line contains three space separated in tegers.The First integer,U(0<=U<N),is the index of node U. The second integer,V(0<=v<N,V!=U),is the node V.The third integer,W (1<=W<=1000),is th capacity (weight) of path from U to V.
Output
Sample Input
1
1 7 11 0 6
0 1 3
0 3 3
1 2 4
2 0 3
2 3 1
2 4 2
3 4 2
3 5 6
4 1 1
4 6 1
5 6 9
Sample Output
1 1.667
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
};
arc e[maxn*];
int head[maxn],d[maxn],cur[maxn],tot,s,t,n;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
for(int i = ; i <= n; ++i) d[i] = -;
q.push(s);
d[s] = ;
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[t] > -;
}
int dfs(int u,int low){
if(u == t) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == d[u] + && (a = dfs(e[i].to,min(e[i].flow,low)))){
e[i].flow -= a;
e[i^].flow += a;
tmp += a;
low -= a;
break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
bool vis[maxn];
int maxcap;
void dfs2(int u){
vis[u] = true;
for(int i = head[u]; ~i; i = e[i].next){
if(!vis[e[i].to]){
maxcap = max(maxcap,e[i^].flow);
if(e[i^].flow == ){
cout<<u<<" "<<e[i].to<<endl;
}
dfs2(e[i].to);
}
}
}
int main(){
int p,cs,m,u,v,cap;
scanf("%d",&p);
while(p--){
scanf("%d %d %d %d %d",&cs,&n,&m,&s,&t);
memset(head,-,sizeof(head));
for(int i = tot = ; i < m; ++i){
scanf("%d %d %d",&u,&v,&cap);
add(u,v,cap);
}
int ans = ,o;
maxcap = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
o = dfs(s,INF);
ans += o;
maxcap = max(maxcap,o);
}
memset(vis,false,sizeof(vis));
//maxcap = 0;
//dfs2(s);
printf("%d %.3f\n",cs,ans*1.0/maxcap);
//cout<<ans<<" "<<maxcap<<endl;
}
return ;
}
HDU 4240 Route Redundancy的更多相关文章
- hdu 4240 Route Redundancy 最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 A city is made up exclusively of one-way steets. ...
- hdu 4240(最大流+最大流量的路)
Route Redundancy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4240在(最大流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Max ...
- HDU 4240
http://acm.hdu.edu.cn/showproblem.php?pid=4240 题意:求最大流和流量最大的一条路径的流量的比值 题解:流量最大的路径的流量在dinic的dfs每次搜到终点 ...
- hdu 4240 最大流量路径
题意弄了半天: 给出一个有向图,带边权,src,dst. 求出src到dst的最大流,再求出从src到dst流量最大的路径的流量,求它们的比值. #include <cstdio> #in ...
- VRRP协议:Virtual Route
VRRP协议:Virtual Route Redundancy Protocol虚拟路由冗余协议.是一种容错协议,保证当主机的下一跳路由出现故障时,由另一台路由器来代替出现故障的路由器进行工作,从而 ...
- keepalived的安装和使用
IP配置 管理IP地址 角色 备注 网卡 192.168.1.114 主调度器(Director) 对外提供VIP服务的地址为192.168.1.88 eth1 192.168.1.205 备用调度器 ...
- keepalived工作原理
keepalived是一个类似于Layer2,4,7交换机制的软件.是Linux集群管理中保证集群高可用的一个服务软件,其功能是用来防止单点故障. keepalived的工作原理: ...
- 《nginx 四》双机主从热备
lvs+keepalived+nginx实现高性能负载均衡集群 LVS作用 LVS是一个开源的软件,可以实现传输层四层负载均衡.LVS是Linux Virtual Server的缩写,意思是Linux ...
随机推荐
- A - Jungle Roads
A - Jungle Roads 思路:并查集的板子,重点是字符的转换,不能忘了加上1. #include<cmath> #include<cstdio> #include&l ...
- 解决Unity的 The file 'MemoryStream' is corrupted! Remove it and launch 崩溃问题
孙广东 2015.7.30 问题: 在项目平时删除资源或者脚本资源时产生的prefab的脚本引用丢失,特别是在场景scene中丢了解决方式/// 1.又一次Clone项目/// 2.删除项目的 ...
- 使用gridlayout布局后,因某些原因又删除,并整理文件夹结构时,Unable to resolve target 'android-7'
出现的问题 [2013-01-11 10:52:39 - gridlayout_v7] Unable to resolve target 'android-7' 事由:在一次做九宫格时.误使用了gri ...
- NHibernate之旅(14):探索NHibernate中使用视图
本节内容 引入 1.持久化类 2.映射文件 3.測试 结语 引入 在数据库操作中,我们除了对表操作,还有视图.存储过程等操作,这一篇和下篇来学习这些内容.这篇我们来学习怎样在NHibernate中使用 ...
- 软件測试、ios中的測试概念以及步骤
软件測试: 软件測试的目标是应该服务于软件项目的目标,能够通过建议反馈使用更加高效的方法和工具,提升软件开发效率以及软件开发质量.同一时候还能够通过过一些手段,更早.更快.很多其它地发现缺陷.从容减少 ...
- 高校学生学籍系统C++&mysql
/* C++程序设计实践教学环节任务书 一.题目:高校学籍管理系统 二.目的与要求 1. 目的: 1.掌握C++语言基本知识及其编程方法 2.掌握类和对象的基本概念与用法 3.掌握面向对象中的继承与 ...
- C# 监控Windows睡眠与恢复
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; private void SystemEvents_PowerModeC ...
- ComponentName
ComponentName,顾名思义,就是组件名称,通过调用Intent中的setComponent方法,我们可以打开另外一个应用中的Activity或者服务. 实例化一个ComponentName需 ...
- ES 處於“initializing”狀態,此時主節點正在嘗試將分片分配到集群中的數據節點。 如果您看到分片仍處於初始化或未分配狀態太長時間,則可能是您的集群不穩定的警告信號。
指標要點: Cluster status: 如果集群狀態為黃色,則至少有一個副本分片未分配或丟失. 搜索結果仍將完成,但如果更多的分片消失,您可能會丟失數據. 紅色的群集狀態表示至少有一個主分片丟失, ...
- 微信小程序分享朋友圈的实现思路与解决办法
实现思路 那么既然小程序没有分享到朋友圈的api,我们怎么实现分享到朋友圈呢,下面我介绍一下实现思路. 既然没有捷径,那就走复杂一点的路线,那就是需要用户手动分享到朋友圈,问题又来了,用户手动分享的话 ...