HDU4240_Route Redundancy
题目很简单、给一个有向图,求两点间的最大流量与任意一条路中的最大流量的比值。
最大流不说了,求出单条流量最大的路径可以用类似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的更多相关文章
- 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 ...
- hdu 4240 Route Redundancy 最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 A city is made up exclusively of one-way steets. ...
- memcache redundancy机制分析及思考
设计和开发可以掌控客户端的分布式服务端程序是件幸事,可以把很多事情交给客户端来做,而且可以做的很优雅.角色决定命运,在互联网架构中,web server必须冲锋在前,注定要在多浏览器版本以及协议兼容性 ...
- CRC(Cyclic Redundancy Check)循环冗余校验码与海明码的计算题
(17)采用CRC进行差错校验,生成多项式为G(X)=X4+X+1,信息码字为10111,则计算出的CRC校验码是 (17) .A.0000 B.0100 C.0010 D.1100试题 ...
- 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 ...
- 【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 ...
- 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 ...
- HDU 4240 Route Redundancy
Route Redundancy Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...
- 【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 ...
随机推荐
- IT程序员每天的困扰:这TM为啥不可以?这TM也行?
如果有对 Python 感兴趣的程序员,可以加我们小助手的QQ:979950755 会免费送 Python 的视频教程噢! 随着IT互联网对社会的影响越来越重要,关乎人类的未来发展进程.所以现在很多媒 ...
- 用docsify快速构建文档,并用GitHub Pages展示
什么是docsify 无需构建,写完 markdown 直接发布成文档,写说明文档的极佳选择. 快速上手 安装 npm i docsify-cli -g docsify init docs 创建项目 ...
- Redis之数据类型大全
一:String类型 1.set方法:设置key对应的值为string类型的value,如果该key已经存在,则覆盖key对应的value值.所以在redis中key只能有一个. 127.0.0.1: ...
- 执行sh脚本报“/usr/bin/env: "sh\r": 没有那个文件或目录”错误
出现这个错误的原因是出错的语句后面多了“\r”这个字符,换言之,脚本文件格式的问题,我们只需要把格式改成unix即可: vi xx.sh :set ff :set ff=unix :wq!
- SQL查询语句大全及其理解
转自:https://www.cnblogs.com/1234abcd/p/5530314.html 一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删 ...
- python函数式编程,性能,测试,编码规范
这篇文章主要是对我收集的一些文章的摘要.因为已经有很多比我有才华的人写出了大量关于如何成为优秀Python程序员的好文章. 我的总结主要集中在四个基本题目上:函数式编程,性能,测试,编码规范.如果一个 ...
- Redis的C语言客户端(hiredis)的安装和使用
关键词:hiredis, cRedis, redis clients, redis客户端, C客户端, 华为云分布式缓存服务 hiredis是一个非常全面的C语言版redis接口库,支持所有命令.管道 ...
- DDMS_Threads的简单使用
title: DDMS_Threads的简单使用 date: 2016-07-20 00:44:35 tags: [DDMS] categories: [Tool,IDE] --- 概述 本文记录在 ...
- nodejs加载模块心得,mongoose的继承,schematype的mixd介绍
1. require("xxx")可以是原生模块, 也可以是根目录“/node_modules”下的某个模块 2. 多个模块的package.json使用同一个相同模块的时候,将改 ...
- 北美跨境电商平台Wish透露未来一年在华规划
9月12日,北美跨境电商平台Wish在深圳透露了未来一年在中国区的重点规划.Wish中国区总裁丁浩川表示,在下一阶段,Wish公司将继续围绕 提升平台流量. 加强品类支撑. 深化库存管理. 推进物流改 ...