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 ...
随机推荐
- ContestHunter暑假欢乐赛 SRM 02
惨不忍睹 3个小时都干了些什么... 日常按顺序从A题开始(难度居然又不是递增的 第一眼A题就觉得很简单...写到一半才发现woc那是个环.感觉一下子复杂了,按照链的方法扩展的话要特判很多东西... ...
- oracle-java7-installer安装java失败之后的处理
最开始尝试使用installer安装jdk7,但是未能进行完整,之后每次安装软件都会报错,说oracle-java7-installer处有错误,查得如下解决办法: sudo rm /var/lib/ ...
- JavaScript定义类的方式与其它OO语言有些差异
JavaScript面向对象的程序编写与其它OO语言有一些出入,所以使用JavaScript的面向对象特性的时候,需要注意一些规范性的问题.下面就简单地谈一下,JavaScript如何定义一个类,在定 ...
- [POI2007] ZAP-Queries (莫比乌斯反演)
[POI2007] ZAP-Queries 题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian S ...
- SPOJ - HIGH :Highways (生成树计数)
Highways 题目链接:https://vjudge.net/problem/SPOJ-HIGH Description: In some countries building highways ...
- zigbee ------ JN5169低功耗设置
低功耗睡眠设置Power Manager (PWRM) PWRM_vInit() 如果进入睡眠模式,设置芯片进入何种睡眠模式 PWRM_eScheduleActivity()设置进入睡眠多长时间(时钟 ...
- Spring------mysql读写分离
1. 为什么要进行读写分离 大量的JavaWeb应用做的是IO密集型任务, 数据库的压力较大, 需要分流 大量的应用场景, 是读多写少, 数据库读取的压力更大 一个很自然的思路是使用一主多从的数据库集 ...
- PostHtml 中的一些有用的插件
记录一下 PostHtml 中的一些比较有用的插件 参考自PostHtml文档 posthtml-pug 将pug转化成html posthtml-md 将md语法转化为html语法 posthtml ...
- idea 导入 java json 包
1.java 项目导包 找到 External Libraries 下面的java版本包,在点击鼠标右键.直接找到jar路径全部选中导入即可.
- 如何创建和销毁对象(Effective Java 第二章)
最近有在看Effective Java,特此记录下自己所体会到的东西,写篇博文会更加的加深印象,如有理解有误的地方,希望不吝赐教. 这章主题主要是介绍:何时以及如何创建对象,何时以及如何避免创建对象, ...