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 点和一个 ...
随机推荐
- 在VS中快速查看文件被谁签出
步骤如下: 1 在VS中的菜单上单击鼠标右键,然后选择显示“源代码管理” 2 选中要查看的文件后,在源代码管理中单击“属性” 3 打开第2个标签页“Check Out Status”,可以看到签出人等 ...
- winform中嵌入Ppt、Word、Excel
1.下载DsoFramer_KB311765_x86.exe 2.安装,默认路径安装C:\DsoFramer. 3.注册:开始菜单——>运行 输入:regsvr32 C:\DsoFramer\d ...
- c#获取多个List<class>合并、并将相同条件下的值累计sum
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Gridview 行变色和行按钮调用前端js
1.鼠标移动某一行 ,变色 protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Ro ...
- YARN内存使用优化配置
在Hadoop2.0中, YARN负责管理MapReduce中的资源(内存, CPU等)并且将其打包成Container. 这样可以精简MapReduce, 使之专注于其擅长的数据处理任务, 将无需考 ...
- js闭包理解实例小结
Js闭包 闭包前要了解的知识 1. 函数作用域 (1).Js语言特殊之处在于函数内部可以直接读取全局变量 <script type="text/javascript"> ...
- SPARK 数据统计程序性能优化。
昨天写完R脚本 没测试就发到博客里, 结果实际运行发现很慢,运行时间在2小时以上, 查看spark控制台, 大量时间消耗在count上, 产生的stage多大70多个 . 分析原因. 1 selec ...
- 第六章 管理类型(In .net4.5) 之 创建类型
1. 概述 本章内容包括 C#5中如何更好的创建类型以及如何扩展现有类型. 2. 主要内容 2.1 如何选择类型 C#类型系统包括三种类型:值类型.引用类型.指针类型.(指针类型用于非托管代码,很少使 ...
- 1.css的语法标准
css(Cascading Style Sheets),中文名称为层叠样式表,主要用于对html的样式设置. 在使用CSS的时候,要注意其优先级情况,优先级由下所示(数字越高,优先级越高): 浏览器缺 ...
- SRF之数据验证
实现表单输入数据的验证,包括客户端验证和服务器端验证 如何使用 数据验证在业务层的实体类字段上增加数据验证的特性,例如 public class User { [Required(ErrorMessa ...