hdu 4240(最大流+最大流量的路)
Route Redundancy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 625 Accepted Submission(s): 367
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.
first line of input contains asingle integer P,(1<=P<=1000),which
is the number of data sets that follow.Each data set consists of
several lines and represents a directed graph with positive integer
weights.
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.
each data set there is one line of output.It contains the date set
number(N) follow by a single space, followed by a floating-point value
which is the minimum redundancy ratio to 3 digits after the decimal
point.
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
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
const int INF = ;
struct Edge{
int v,w,next;
}edge[N*N];
int head[N];
int level[N];
int tot,max_increase;
void init()
{
memset(head,-,sizeof(head));
tot=;
}
void addEdge(int u,int v,int w,int &k)
{
edge[k].v = v,edge[k].w=w,edge[k].next=head[u],head[u]=k++;
edge[k].v = u,edge[k].w=,edge[k].next=head[v],head[v]=k++;
}
int BFS(int src,int des)
{
queue<int>q;
memset(level,,sizeof(level));
level[src]=;
q.push(src);
while(!q.empty())
{
int u = q.front();
q.pop();
if(u==des) return ;
for(int k = head[u]; k!=-; k=edge[k].next)
{
int v = edge[k].v;
int w = edge[k].w;
if(level[v]==&&w!=)
{
level[v]=level[u]+;
q.push(v);
}
}
}
return -;
}
int dfs(int u,int des,int increaseRoad){
if(u==des||increaseRoad==) {
return increaseRoad;
}
int ret=;
for(int k=head[u];k!=-;k=edge[k].next){
int v = edge[k].v,w=edge[k].w;
if(level[v]==level[u]+&&w!=){
int MIN = min(increaseRoad-ret,w);
w = dfs(v,des,MIN);
if(w > )
{
edge[k].w -=w;
edge[k^].w+=w;
ret+=w;
if(ret==increaseRoad){
return ret;
}
}
else level[v] = -;
if(increaseRoad==) break;
}
}
if(ret==) level[u]=-;
return ret;
}
int Dinic(int src,int des)
{
int ans = ;
while(BFS(src,des)!=-) ans+=dfs(src,des,INF);
return ans;
}
int d,n,m,src,des;
bool vis[N];
void dfs1(int u,int ans){
if(u==des){
max_increase = max(max_increase,ans);
return ;
}
for(int k=head[u];k!=-;k=edge[k].next){
int v = edge[k].v,w = edge[k].w;
if(!vis[v]){
vis[v] = true;
dfs1(v,min(w,ans)); ///最大流量由最小容量边决定
vis[v] = false;
}
}
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
init();
max_increase = -;
scanf("%d%d%d%d%d",&d,&n,&m,&src,&des);
for(int i=;i<=m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
addEdge(u,v,w,tot);
}
memset(vis,false,sizeof(vis));
dfs1(src,); ///deal
int max_flow = Dinic(src,des);
printf("%d %.3lf\n",d,max_flow*1.0/max_increase);
}
return ;
}
hdu 4240(最大流+最大流量的路)的更多相关文章
- hdu 3549 Flow Problem【最大流增广路入门模板题】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others ...
- HDU 1532 最大流入门
1.HDU 1532 最大流入门,n个n条边,求第1点到第m点的最大流.只用EK做了一下. #include<bits/stdc++.h> using namespace std; #pr ...
- 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在(最大流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Max ...
- hdu 4240 最大流量路径
题意弄了半天: 给出一个有向图,带边权,src,dst. 求出src到dst的最大流,再求出从src到dst流量最大的路径的流量,求它们的比值. #include <cstdio> #in ...
- hdu 4289 最大流拆点
大致题意: 给出一个又n个点,m条边组成的无向图.给出两个点s,t.对于图中的每个点,去掉这个点都需要一定的花费.求至少多少花费才能使得s和t之间不连通. 大致思路: 最基础的拆点最大 ...
- hdu 3549 Flow Problem(增广路算法)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 模板题,白书上的代码... #include <iostream> #include & ...
- HDU 4240
http://acm.hdu.edu.cn/showproblem.php?pid=4240 题意:求最大流和流量最大的一条路径的流量的比值 题解:流量最大的路径的流量在dinic的dfs每次搜到终点 ...
- HDU 4240 Route Redundancy
Route Redundancy Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...
随机推荐
- 【简单算法】37.Shuffle an Array
题目: 打乱一个没有重复元素的数组. 示例: // 以数字集合 1, 2 和 3 初始化数组. ,,}; Solution solution = new Solution(nums); // 打乱数组 ...
- JavaScript颜色选择器的实现
下面的JavaScript取色器可以方便网页设计取色,同时也可以看一下,网上常见的取色器是如何实现的.这里只给出了核心的JavaScript代码,其它部分比如CSS可以参照本页的源代码. JavaSc ...
- k好数 数位dp
问题描述 如果一个自然数N的K进制表示中任意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数.求L位K进制数中K好数的数目.例如K = 4,L = 2的时候,所有K好数为11.13.20.22 ...
- 【IntelliJ IDEA 12使用】导入外部包
以前用eclipse,现在用IntelliJ IDEA,发现它确实是个很不错的工具. 用IntelliJ IDEA12这个版本导入外部JAR包,这样来操作,打开Project Structure,在m ...
- java 课后作业
杨辉三角 组合数 public class YH { public static void main(String agrs[]) { int a[5][5],i,j; for(i = 0;i < ...
- win下删除oracle
关掉oralce服务. 具体方式有两种: 1.命令行下使用命令关闭服务:net stop OracleServiceORCL ,ORCL是我的实例名字,换成你的) 2.运行services.msc到系 ...
- maven项目执行run as/maven install时提示找不到包
选中项目,右键 右键项目->MAVEN->Update Project,如下图 点击ok,clean相关项目,再打包.如果还是不行看一下你jdk 的版本和你编译的版本是否一致
- linux sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory.这是不同系统编码格式引起的:在windows系统中编辑的. ...
- 【点分治练习题·不虚就是要AK】点分治
不虚就是要AK(czyak.c/.cpp/.pas) 2s 128M by zhb czy很火.因为又有人说他虚了.为了证明他不虚,他决定要在这次比赛AK. 现在他正在和别人玩一个游戏:在一棵树上 ...
- Vuejs - 花式渲染目标元素
Vue.js是什么 摘自官方文档: Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库 ...