http://acm.hdu.edu.cn/showproblem.php?pid=4240

题意:求最大流和流量最大的一条路径的流量的比值

题解:流量最大的路径的流量在dinic的dfs每次搜到终点的时候更新最大值

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std; const int INF=0xfffffff ;
struct node
{
int s,t,cap,nxt ;
}e[] ;
int m,n,cnt,head[],level[],q[],maxn ;
void add(int s,int t,int cap)
{
e[cnt].s=s ;e[cnt].t=t ;e[cnt].cap=cap ;e[cnt].nxt=head[s] ;head[s]=cnt++ ;
e[cnt].s=t ;e[cnt].t=s ;e[cnt].cap= ;e[cnt].nxt=head[t] ;head[t]=cnt++ ;
}
bool build(int s,int t)
{
int front=,rear= ;
memset(level,-,sizeof(level)) ;
q[rear++]=s ;
level[s]= ;
while(front<rear)
{
int u=q[front++] ;
for(int i=head[u] ;i!=- ;i=e[i].nxt)
{
int tt=e[i].t ;
if(level[tt]==- && e[i].cap>)
{
level[tt]=level[u]+ ;
if(tt==t)return true ;
q[rear++]=tt ;
}
}
}
return false ;
}
int find(int s,int t,int flow)
{
if(s==t)
{
maxn=max(maxn,flow) ;
return flow ;
}
int ret=,a ;
for(int i=head[s] ;i!=- ;i=e[i].nxt)
{
int tt=e[i].t ;
if(level[tt]==level[s]+ && e[i].cap>)
{
a=find(tt,t,min(e[i].cap,flow-ret)) ;
e[i].cap-=a ;
e[i^].cap+=a ;
ret+=a ;
if(ret==flow)
return ret ;
}
}
if(!ret)level[s]=- ;
return ret ;
}
int dinic(int s,int t)
{
int flow,ret= ;
while(build(s,t))
while(flow=find(s,t,INF))
ret+=flow ;
return ret ;
}
int main()
{ int N,S,T,cas ;
scanf("%d",&cas) ;
while(cas--)
{
scanf("%d%d%d%d%d",&N,&n,&m,&S,&T) ;
memset(head,-,sizeof(head)) ;
cnt= ;
maxn= ;
while(m--)
{
int s,t,v ;
scanf("%d%d%d",&s,&t,&v) ;
add(s,t,v) ;
}
printf("%d %.3f\n",N,dinic(S,T)*1.0/maxn) ;
}
return ;
}

HDU 4240的更多相关文章

  1. hdu 4240 Route Redundancy 最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 A city is made up exclusively of one-way steets. ...

  2. hdu 4240在(最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Max ...

  3. HDU 4240 Route Redundancy

    Route Redundancy Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...

  4. hdu 4240 最大流量路径

    题意弄了半天: 给出一个有向图,带边权,src,dst. 求出src到dst的最大流,再求出从src到dst流量最大的路径的流量,求它们的比值. #include <cstdio> #in ...

  5. hdu 4240(最大流+最大流量的路)

    Route Redundancy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. Could not find a package configuration file provided by 'ecl_geometry' ,.................couldn't find required component 'ecl_geometry'

    sudo apt-get install ros-kinetic-ecl-geometry

  2. Activity生命周期之我见

    关于Activity生命周期的文章很多,而且大部分也说得很详细,所以作为关于这方面的内容我本来不想多说,但是大家可能跟我之前一样,在看这方面的内容的时候都能很容易地看懂,但是过几天又忘了,或者在用的程 ...

  3. R语言-attach、detach、with

    在R语言中,对于串列,数据框中的数据的进行操作时,为了避免重复地键入对象名称,可使用attach或with. 1.attach() 假设data.frame包含列name,age attach(one ...

  4. 20170731xlVba根据数据表和模板表生成新表

    Public Sub SplitData() Dim Wb As Workbook Dim Sht As Worksheet Dim NewSht As Worksheet Dim arr As Va ...

  5. mtime 的具体解释

    find . -mtime +0 # find files modified greater than 24 hours ago find . -mtime 0 # find files modifi ...

  6. android之视频播放系统VideoView和自定义VideoView控件的应用

    Android播放视频,包含系统自带VideoView控件,和自定义VideoView控件,可全屏播放,案例包含了本地视频和网络视频. 1:自定义VideoView控件 2:布局代码 3:Activi ...

  7. 安卓本地化之SharedPreferences

    SharedPreferences的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息,用Sqlite数据库来存放并不划算,因为数据库连接跟操作等耗时大大影响了程序的 ...

  8. windows下apache利用SSL来配置https

    第一步打开httpd.conf文件找到以下两个变量把注释去掉. #LoadModule ssl_module modules/mod_ssl.so (去掉前面的#号) #Include conf/ex ...

  9. ccf交通规划

    一.试题 问题描述  G国国王来中国参观后,被中国的高速铁路深深的震撼,决定为自己的国家也建设一个高速铁路系统.  建设高速铁路投入非常大,为了节约建设成本,G国国王决定不新建铁路,而是将已有的铁路改 ...

  10. UVA-701 The Archeologists' Dilemma (数论)

    题目大意:给了一个2^E的前缀n,已知前缀n的位数不到2^E的位数的一半,找出满足条件的最小E. 题目解析:设2^E为i位数,则有n*10^i<2^E<(n+1)*10^i.解不等式得到i ...