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 ...
随机推荐
- 中间介(MiddleWare)
引子-Django的生命周期 在学习中间介之前,我们先来回顾一下Django的生命周期:用户发起请求,请求会被发送到urlconf中的url,然后会指向对应的views函数进行处理,views函数处理 ...
- Idea for Mac 快捷键(快捷键选择:Mac OS X 10.5+)
删除一行 command + delete 查找 command + f 查找替换 command + r 复制一行 comma ...
- 使用html2canvas将html标签转化为图片
有些时候我们无法用常规的截图工具截取网页内容,这时可以尝试以下方法: 1.首先允许跨域,Chrome浏览器可以在快捷方式->属性->目标栏里添加: --disable-web-securi ...
- Unity3D画面渲染官方教程(一)对光照和渲染的介绍
本系列是对官方教程的翻译加上自己的一些理解译著的,官方网址:https://unity3d.com/cn/learn/tutorials/s/graphics 翻译上尽量保证准确性,但不排除省略或者添 ...
- 在eclipse中修改项目发布tomcat的路径名
第一种.右键点击项目,选中Properties 第二种.双击tomcat 保存 第三种.修改项目目录下的 .setting目录下的
- SQL Server存储过程用法介绍
存储过程其实就是已预编译为可执行过程的一个或多个SQL语句. 通过调用和传递参数即可完成该存储过程的功能. 前面有介绍过存储过程的一些语法,但是没有详细示例,今天我们来一起研究一下存储过程. 提高性能 ...
- 6.把建模工具导出的dea文件导入到three.js程序中
1.使用Three.js渲染导出的DAE 在Three.js中使用Collada(即.dae)文件的话,首先得要用到 ColladaLoader.js. 但是这个ColladaLoader.js并不包 ...
- phpcms 容许英文目录有空格
在PHPCMS添加栏目里面,有个选项是 英文目录,这里目录可以用作伪静态功能.这么英文不能有空格等特殊字符.但是如果页面中需要引用包含空格的字符呢,例如,关于我们页面,我要显示英文about us.那 ...
- leetcode第217.题存在重复元素
1.题目描述 给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 2.示例 2.1 输入: [1,2,3,1 ...
- python—多任务版udp聊天机器人
将多任务(多线程)引入到udp聊天机器人,可以实现同时发送消息和接收消息 import socket import threading def udp_send(udp_socket,ip,port) ...