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 ...
随机推荐
- POJ 4786 Fibonacci Tree
Fibonacci Tree Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...
- CF409C Magnum Opus
CF409C Magnum Opus 题意翻译 题目背景 愚人节题目,题面似乎是一位名叫Nicolas Flamel的炼金术士用拉丁文写的某种物质的配方,结合谷歌尝试翻译了一下: 吾友: 哲人石所言不 ...
- spring是怎样管理mybatis的及注入mybatis mapper bean的
1.spring启动mybatis的两个重要类:SqlSessionFactoryBean和MapperFactoryBean,这两个类都是org.mybatis.spring jar包的. 是用来启 ...
- 低调、奢华、有内涵的敏捷式大数据方案:Flume+Cassandra+Presto+SpagoBI
基于FacebookPresto+Cassandra的敏捷式大数据 文件夹 1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 2 2.1 2.2 2.3 2.4 2.5 2.6 3 ...
- poj 2683 Ohgas' Fortune 利率计算
水题. 代码: //poj 2683 //sep9 #include <iostream> using namespace std; int main() { int cases; sca ...
- 学习ASP.NET MVC系列 - 还有比这更简炼的吗?把复杂的事情变简单了,贡献啊!
转自
- WPF Prefix 'attach' does not map to a namespace.
这个是用附加属性时,一定要在属性前面加Path= Visibility="{Binding Path=PlacementTarget.(attach:CommonAttachedProper ...
- Unable to access the IIS metabase
https://stackoverflow.com/questions/12859891/error-unable-to-access-the-iis-metabase 解决方法1 On Window ...
- Linux,Docker,Jenkins No such file or directory
你们先休息下,我先哭哭! 今天在做交接项目的bug修改的时候,在创建文件的时候报错 No such file or directory 然后跟着路径去linux中查看了该路径,但确实存在,并且权限都是 ...
- lightshot截图工具的安装及使用
通常我们做PPT或者写博客难免要用到截图工具,而Windows自带的snippingtool启动有延迟也不够方便,QQ有截屏又需要联网及登录情况下,于是我想着在Chrome上搜一款清新简洁的截屏软件, ...