题目很简单、给一个有向图,求两点间的最大流量与任意一条路中的最大流量的比值。

最大流不说了,求出单条流量最大的路径可以用类似Spfa的方法来搞,保存到达当前点的最大流量,一直往下更新即可。

召唤代码君:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define maxn 1010
#define Inf ~0U>>1
using namespace std; vector<int> v[maxn];
int c[maxn][maxn],tag[maxn],d[maxn],a[maxn][maxn],f[maxn];
int n,m,s,t,ans,cap,cas,D,U,V,W;
int Q[maxn],bot,top;
bool can[maxn]; void _init()
{
ans=cap=0;
for (int i=1; i<=n; i++)
{
v[i].clear();
for (int j=1; j<=n; j++) c[i][j]=a[i][j]=0;
}
} void bfs()
{
for (int i=1; i<=n; i++) d[i]=9999,can[i]=false;
Q[bot=top=1]=t,d[t]=0;
while (bot<=top)
{
int cur=Q[bot++];
for (unsigned i=0; i<v[cur].size(); i++)
{
if (c[v[cur][i]][cur]<=0 || d[cur]+1>=d[v[cur][i]]) continue;
d[v[cur][i]]=d[cur]+1,Q[++top]=v[cur][i];
}
}
} int dfs(int cur,int num)
{
if (cur==t)
{
cap=max(cap,num);
return num;
}
int k,tmp=num;
for (unsigned i=0; i<v[cur].size(); i++)
{
if (c[cur][v[cur][i]]<=0 || can[v[cur][i]] || d[cur]!=d[v[cur][i]]+1)
continue;
k=dfs(v[cur][i],min(num,c[cur][v[cur][i]]));
if (k) c[cur][v[cur][i]]-=k,c[v[cur][i]][cur]+=k,num-=k;
if (num==0) break;
}
if (num) can[cur]=true;
return tmp-num;
} void maxedge(int cur,int num)
{
if (num>f[cur]) f[cur]=num;
else return;
if (cur==t) return;
for (unsigned i=0; i<v[cur].size(); i++)
maxedge(v[cur][i],min(num,a[cur][v[cur][i]]));
} int main()
{
//freopen("data.in","rb",stdin);
scanf("%d",&cas);
while (cas--)
{
scanf("%d%d%d%d%d",&D,&n,&m,&s,&t);
s++,t++;
_init();
while (m--)
{
scanf("%d%d%d",&U,&V,&W);
U++,V++;
/*
if (tag[U]!=D || tag[V]!=D) a[U][V]=a[V][U]=c[U][V]=c[V][U]=0;
if (tag[U]!=D) v[U].clear(),tag[U]=D;
if (tag[V]!=D) v[V].clear(),tag[V]=D;
*/
c[U][V]+=W,a[U][V]+=W;
v[U].push_back(V),v[V].push_back(U);
}
for (bfs(); d[s]<n; bfs()) ans+=dfs(s,Inf);
for (int i=1; i<=n; i++) f[i]=cap;
maxedge(s,Inf);
printf("%d %.3f\n",D,ans*1.0/max(f[t],cap));
}
return 0;
}

  

HDU4240_Route Redundancy的更多相关文章

  1. hdu 1082, stack emulation, and how to remove redundancy 分类: hdoj 2015-07-16 02:24 86人阅读 评论(0) 收藏

    use fgets, and remove the potential '\n' in the string's last postion. (main point) remove redundanc ...

  2. hdu 4240 Route Redundancy 最大流

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

  3. memcache redundancy机制分析及思考

    设计和开发可以掌控客户端的分布式服务端程序是件幸事,可以把很多事情交给客户端来做,而且可以做的很优雅.角色决定命运,在互联网架构中,web server必须冲锋在前,注定要在多浏览器版本以及协议兼容性 ...

  4. CRC(Cyclic Redundancy Check)循环冗余校验码与海明码的计算题

    (17)采用CRC进行差错校验,生成多项式为G(X)=X4+X+1,信息码字为10111,则计算出的CRC校验码是  (17)  .A.0000  B.0100   C.0010   D.1100试题 ...

  5. iSCSI Network Designs: Part 5 – iSCSI Multipathing, Host Bus Adapters, High Availability and Redundancy

    iSCSI Network Designs: Part 5 – iSCSI Multipathing, Host Bus Adapters, High Availability and Redunda ...

  6. 【RAC搭建报错】You need disks from at least two different failure groups, excluding quorum disks and quorum failure groups, to create a Disk Group with normal redundancy

    报错: You need disks from at least two different failure groups, excluding quorum disks and quorum fai ...

  7. O/S-Error: (OS 23) Data error (cyclic redundancy check)问题处理

    RMAN-03002: backup plus archivelog 命令 (在 08/24/2015 03:31:00 上) 失败ORA-19501: 文件 "XXXXXX.DBF&quo ...

  8. HDU 4240 Route Redundancy

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

  9. 【IJCAI2020】Split to Be Slim: An Overlooked Redundancy in Vanilla Convolution

    Split to Be Slim: An Overlooked Redundancy in Vanilla Convolution, IJCAI 2020 论文地址: https://arxiv.or ...

随机推荐

  1. Git命令简单总结

    集中式vs分布式 svn集中式:版本库是集中存放在中央服务器的,需要联网才能工作 git 分布式:每个人的电脑上都是一个完整的版本库 和集中式版本控制系统相比,分布式版本控制系统的安全性要高很多,因为 ...

  2. axios的简单使用

    axios是一个通用的ajax请求库,vue 2.0以后,推荐使用axios Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 使用: 1.下载安装 n ...

  3. Maven仓库 - 分发构件至远程仓库

    分发构件至远程仓库   mvn install 会将项目生成的构件安装到本地Maven仓库,mvn deploy 用来将项目生成的构件分发到远程Maven仓库.本地Maven仓库的构件只能供当前用户使 ...

  4. 人脸识别-关于face_recognition库的安装

    首先十分感谢博客https://blog.csdn.net/scc_722/article/details/80613933,经历过很多尝试(快要醉了),终于看了这篇博客后安装成功. face_rec ...

  5. 使用着色器在WebGL3D场景中呈现行星表面地形

    实验目的:按照一定规律生成类地行星地表地形区块,并用合理的方式将地形块显示出来 涉及知识:Babylon.js引擎应用.着色器编程.正态分布.数据处理.canvas像素操作 github地址:http ...

  6. Linux AD 身份统一验证(SSO)

    http://www.toxingwang.com/linux-unix/linux-admin/584.html Linux+samba-winbind+AD实现统一认证 2013年04月27日 ⁄ ...

  7. JetBrains激活 PyCharm | IntelliJ IDEA | CLion | WebStorm...

    最近,JetBrains的IDE火了起来,身为学Java的人,放弃了Eclipse,选择了Idea,还真有点不舍得呢... 虽然Idea不错(在我看来,比Eclipse好用),但是,人家是收费的呀.. ...

  8. RHEL7 利用双网卡绑定实现VLAN

    使用nmcli创建bond配置 #nmcli connection add type bond ifname bond0 con-name bond0 mode active-backup #nmcl ...

  9. 天马行空云计算(二)-Hardware&Hypervisor介绍

    天马行空云计算系列一介绍了总体抽象视图,本篇展开Hardware&Hypervisor 介绍.如下是介绍大纲: 本篇将基于上述架构从如下方面介绍说明 Linux设备驱动 因为上述提到的一些硬件 ...

  10. 学习笔记 | treap | splay

    目录 前言 treap 它的基本操作 前言 不会数据结构选手深深地感受到了来自treap的恶意QwQ 在听的时候感觉自己听得听懂的??大概只是听懂了它的意思 代码是怎么写都感觉写不好╮(╯﹏╰)╭ 菜 ...