HDU 4240

时间:2021-05-21 23:47:30

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&lpar;最大流&plus;最大流量的路&rpar;

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

  6. HDOJ 2111&period; 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&lpar;取模&rpar;

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

随机推荐

  1. K-近邻算法(KNN)

    简介 k近邻算法是数据分类一种常用的算法,属于监督学习算法的一类,它采用不同特征值之的距离进行分类.K近邻算法具有精度高.对异常值不敏感.无数据输入假定的优点,缺点是计算复杂度高.空间复杂度高.适用于 ...

  2. jQuery LigerUI系列:ligerComboBox

    1. ligerComboBox参数.方法及事件 1.1 参数 2. ligerComboBox示例 2.1 初始化HTML select控件 <link href="/Scripts ...

  3. 完成卸载vs2010后再安装

    在安装好vs2010后,更改了驱动器号,造成vs工具不能使用,所以需要卸载vs2010 使用Microsoft Visual Studio 2010 Uninstall Utility来卸载vs201 ...

  4. 52&period; Sort Colors &amp&semi;&amp&semi; Combinations

    Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...

  5. 详解MySQL---DDL语句、DML语句与DCL语句

    背景:近几年,开源数据库逐渐流行起来.由于具有免费使用.配置简单.稳定性好.性能优良等优点,开源数据库在中低端应用上占据了很大的市场份额,而 MySQL 正是开源数据库中的杰出代表.MySQL 数据库 ...

  6. c&plus;&plus;的历史-异常

    1.异常出现的目的 在c++语言的设计和演化中,Bjarne Stroustrup说过异常的设计假定如下情况: 基本上是为了处理错误 与函数定义相比,异常处理是很少的 与函数调用相比,异常出现的频率较 ...

  7. JQery icheck 插件

    <script type="text/javascript"> $(document).ready(function(){ var callbacks_list = $ ...

  8. systemtap 列出所有linux 内核模块与相关函数1

    阿里云主机 [root@monitor klvl]# uname -aLinux monitor 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20: ...

  9. &lbrack;转载&rsqb; java多线程学习-java&period;util&period;concurrent详解&lpar;一&rpar; Latch&sol;Barrier

    转载自http://janeky.iteye.com/blog/769965     Java1.5提供了一个非常高效实用的多线程包:java.util.concurrent, 提供了大量高级工具,可 ...

  10. JAVA&lowbar;SE基础——1&period;JDK&JRE下载及安装

    这是我学了JAVA来写的第一篇博客: 我首先是在传智播客领了张.毕向东老师的免费JAVA学习光盘来学习! 下面我来教大家安装使用JAVA时候必备的JDK 1.首先上甲骨文公司的官方网站下载JDK的安装 ...