Ombrophobic Bovines - POJ 2391
Description
The farm has F (1 <= F <= 200) fields on which the cows graze.
A set of P (1 <= P <= 1500) paths connects them. The paths are
wide, so that any number of cows can traverse a path in either
direction.
Some of the farm's fields have rain shelters under which the cows
can shield themselves. These shelters are of limited size, so a single
shelter might not be able to hold all the cows. Fields are small
compared to the paths and require no time for cows to traverse.
Compute the minimum amount of time before rain starts that the siren must be sounded so that every cow can get to some shelter.
Input
* Lines 2..F+1: Two space-separated integers that describe a field.
The first integer (range: 0..1000) is the number of cows in that field.
The second integer (range: 0..1000) is the number of cows the shelter
in that field can hold. Line i+1 describes field i.
* Lines F+2..F+P+1: Three space-separated integers that describe a
path. The first and second integers (both range 1..F) tell the fields
connected by the path. The third integer (range: 1..1,000,000,000) is
how long any cow takes to traverse it.
Output
Line 1: The minimum amount of time required for all cows to get under a
shelter, presuming they plan their routes optimally. If it not possible
for the all the cows to get under a shelter, output "-1".
Sample Input
3 4
7 2
0 4
2 6
1 2 40
3 2 70
2 3 90
1 3 120
Sample Output
110
Hint
In 110 time units, two cows from field 1 can get under the shelter
in that field, four cows from field 1 can get under the shelter in field
2, and one cow can get to field 3 and join the cows from that field
under the shelter in field 3. Although there are other plans that will
get all the cows under a shelter, none will do it in fewer than 110 time
units.
const
maxn=;
inf=;
var
first,now,pre,vh,dis,his:array[..maxn*]of longint;
f:array[..maxn,..maxn]of int64;
last,next,liu:array[..maxn*maxn*]of longint;
a,b:array[..maxn]of longint;
n,m,sum,tot:longint; procedure insert(x,y,z:longint);
begin
inc(tot);last[tot]:=y;next[tot]:=first[x];first[x]:=tot;liu[tot]:=z;
inc(tot);last[tot]:=x;next[tot]:=first[y];first[y]:=tot;liu[tot]:=;
end; procedure down(var x:int64;y:int64);
begin
if x>y then x:=y;
end; function flow:longint;
var
i,j,jl,min,aug:longint;
flag:boolean;
begin
for i:= to n<<+ do now[i]:=first[i];
for i:= to n<<+ do vh[i]:=;
for i:= to n<<+ do dis[i]:=;
vh[]:=n<<+;flow:=;
i:=;aug:=inf;
while dis[i]<n<<+ do
begin
his[i]:=aug;
flag:=false;
j:=now[i];
while j<> do
begin
if (liu[j]>) and (dis[i]=dis[last[j]]+) then
begin
if aug>liu[j] then aug:=liu[j];
now[i]:=j;
pre[last[j]]:=j;
i:=last[j];
flag:=true;
if i=n<<+ then
begin
inc(flow,aug);
while i<> do
begin
dec(liu[pre[i]],aug);
inc(liu[pre[i]xor ],aug);
i:=last[pre[i]xor ];
end;
aug:=inf;
end;
break;
end;
j:=next[j];
end;
if flag then continue;
min:=n<<+;
j:=first[i];
while j<> do
begin
if (liu[j]>) and (dis[last[j]]<min) then
begin
min:=dis[last[j]];
jl:=j;
end;
j:=next[j];
end;
dec(vh[dis[i]]);
if vh[dis[i]]= then break;
now[i]:=jl;
dis[i]:=min+;
inc(vh[min+]);
if i<> then
begin
i:=last[pre[i]xor ];
aug:=his[i];
end;
end;
end; procedure main;
var
i,j,k,x,y:longint;
l,r,z,mid,max:int64;
begin
fillchar(f,sizeof(f),);
read(n,m);
for i:= to n do read(a[i],b[i]);
for i:= to n do inc(sum,a[i]);
for i:= to n do f[i,i]:=;
for i:= to m do
begin
read(x,y,z);
if z<f[x,y] then
begin
f[x,y]:=z;
f[y,x]:=z;
end;
end;
for k:= to n do
for i:= to n do
for j:= to n do
down(f[i,j],f[i,k]+f[k,j]);
r:=;
for i:= to n do
for j:= to n do
if (r<f[i,j]) and (f[i,j]<f[,]) then r:=f[i,j];
l:=;max:=r;inc(r);
while l<>r do
begin
mid:=(l+r)>>;
tot:=;
for i:= to n<<+ do first[i]:=;
for i:= to n do insert(,i,a[i]);
for i:= to n do insert(i+n,n<<+,b[i]);
for i:= to n do
for j:= to n do
if f[i,j]<=mid then insert(i,j+n,inf);
if flow>=sum then r:=mid
else l:=mid+;
end;
if l>max then writeln(-)
else writeln(l);
end; begin
main;
end.
Ombrophobic Bovines - POJ 2391的更多相关文章
- poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap
poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...
- POJ 2391 Ombrophobic Bovines
Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18623 Accepted: 4 ...
- poj 2391 Ombrophobic Bovines(最大流+floyd+二分)
Ombrophobic Bovines Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 14519Accepted: 3170 De ...
- POJ 2391 Ombrophobic Bovines (Floyd + Dinic +二分)
Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11651 Accepted: 2 ...
- Ombrophobic Bovines 分类: POJ 图论 最短路 查找 2015-08-10 20:32 2人阅读 评论(0) 收藏
Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16539 Accepted: 3605 ...
- poj2391 Ombrophobic Bovines 拆点+二分法+最大流
/** 题目:poj2391 Ombrophobic Bovines 链接:http://poj.org/problem?id=2391 题意:有n块区域,第i块区域有ai头奶牛,以及一个可以容纳bi ...
- POJ2391:Ombrophobic Bovines(最大流+Floyd+二分)
Ombrophobic Bovines Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 21660Accepted: 4658 题目 ...
- POJ2391 Ombrophobic Bovines(网络流)(拆点)
Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )
一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...
随机推荐
- 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(四)-- Middleware
本文记录了Asp.Net管道模型和Asp.Net Core的Middleware模型的对比,并在上一篇的基础上增加Middleware功能支持. 在演示Middleware功能之前,先要了解一下Asp ...
- Objective-C基本数据类型、表达式和语句
一.基本数据类型 1.一般的计算机语言在定义变量的时候,需要提供给两个内容:类型和名字. 比如:int myClassID; 2.在Xcode中,无论你使用的是GCC编译器还是LLVM编译器,如果我们 ...
- 登录成功返回登录前页面js代码
/*------ setCookie(name,value) -----------*/ function setCookie(name,value) { var Days = 30; //此 coo ...
- Linux之uboot分析与移植20160601
说一下uboot分析与移植: 1.下载.建立source insight工程.编译.烧写.如果无运行分析原因 tar xjf u-boot-2012.04.01.tar.bz2 cd u-boot-2 ...
- 转:OK6410内存及启动流程
一.内存 只是从大体上介绍,并没有涉及寄存器的操作 6410的系统资源为:256MB DDR .2GB NANDFlash 如下图所示: ROM是只读存储器,RAM是随机存储器. 区别: 1.ROM( ...
- python自学笔记一
之前看过一段时间的小甲鱼零基础自学python,b站上有高清免费资源[av4050443],但是作为零基础实在学得艰难,下载了python核心编程pdf,在这里做一些笔记. 虽然使用的是第二版的教材, ...
- Jquery + echarts 使用
常规用法,就不细说了,按照官网一步步来. 本文主要解决问题(已参考网上其他文章): 1.把echarts给扩展到JQuery上,做到更方便调用. 2.多图共存 3.常见的X轴格式化,钻取时传业务实体I ...
- Apache+tomcat集群配置
一.软件准备 Apache 2.2 : http://httpd.apache.org/download.cgi,下载msi安装程序,选择no ssl版本 Tomcat 6.0 : http://to ...
- 用Java实现3DES
3DES,即三重DES,是DES的加强版,也是DES的一个更安全的变形.它使用3个56位(共168位)的密钥对数据进行三次加密,和DES相比,安全性得到了较大的提高. 实际上,3DES是一个过渡的加密 ...
- Windows Phone中使用Native Code
前言 Windows Phone 8 SDK中一个非常有用的特性,就是可以通过Windows Phone Runtime Component (WinPRT)使用C++代码来处理运算量大的任 ...