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

最大流不说了,求出单条流量最大的路径可以用类似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. java日志框架log4j详细配置及与slf4j使用教程

    一.log4j基本用法 首先,配置log4j的jar,maven工程配置以下依赖,非maven工程从maven仓库下载jar添加到“build path” 1 2 3 4 5 <dependen ...

  2. UWP DEP0700: 应用程序注册失败。[0x80073CF9] Install failed. Please contact your software vendor. (Exception from HRESULT: 0x80073CF9)

    现在部署的app项目八成是从以前的一个项目复制过来,修改的.或者本地存在一个相同的app没有卸载. 解决方法: 1. 卸载之前相同的app 2.如果是复制的项目A,但是经过修改后变成了项目B,并且A和 ...

  3. JavaScript 数组——filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()

    filter():   语法: var filteredArray = array.filter(callback[, thisObject]); 参数说明: callback: 要对每个数组元素执行 ...

  4. Mac电脑如何快速下载YouTube视频

    如果你想下载一些教育类的视频资源,或者是一些学习的教程,那么YouTube是一个很好的视频资源平台.YouTube上面各种各样的资源都有,而且质量都很有保证,尤其是那些订阅量很多的人.可惜的是,You ...

  5. Python获取每一位的数字,并返回到列表

    通过计算 def calc(value): result = [] while value: result.append(value % 10) value = value // 10 #逆序,按正常 ...

  6. shell中与运算 cut切分行 if while综合在一起的一个例子

    前言: 公司要统计 treasury库hive表磁盘空间,写了个脚本,如下: 查询hive仓库表占用hdfs文件大小: hadoop fs -du -h  /user/hive/warehouse/t ...

  7. WEB渗透测试基础工具

    代理查询网站:hidemyass(隐藏我的屁股) HTTrack:HTTrack是一个免费和易用的离线浏览工具(浏览器),它可以允许你下载整个WWW网站至本地目录,并且通过遍历网站目录获取HTML,图 ...

  8. 六大iT公司的组织结构

  9. python3去除字符串中括号及括号里面的内容

    a = """ <option value="search-alias=arts-crafts-intl-ship">Arts & ...

  10. js备忘录2

    JavaScript 的类型分为两类,分别是原始类型和对象类型 其中原始类型中只有数字.字符串和布尔型,和java中的有些不一样 null和undefined不是基本数据类型中的某一种 对象是prop ...