Description

FJ's cows really hate getting wet so much that the mere thought of getting caught in the rain makes them shake in their hooves. They have decided to put a rain siren on the farm to let them know when rain is approaching. They intend to create a rain evacuation plan so that all the cows can get to shelter before the rain begins. Weather forecasting is not always correct, though. In order to minimize false alarms, they want to sound the siren as late as possible while still giving enough time for all the cows to get to some shelter.

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

* Line 1: Two space-separated integers: F and P

* 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

OUTPUT DETAILS:

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.

 
 
题目大意
有F个牛棚,和P条道路
每个牛棚能容纳的牛的数量不同,我们要在最短的时间内移动牛,使得所有的牛都能被容纳
 
先floyd出最短路
然后二分时间+网络流判定
 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的更多相关文章

  1. poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap

    poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...

  2. POJ 2391 Ombrophobic Bovines

    Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18623   Accepted: 4 ...

  3. poj 2391 Ombrophobic Bovines(最大流+floyd+二分)

    Ombrophobic Bovines Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 14519Accepted: 3170 De ...

  4. POJ 2391 Ombrophobic Bovines (Floyd + Dinic +二分)

    Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11651   Accepted: 2 ...

  5. Ombrophobic Bovines 分类: POJ 图论 最短路 查找 2015-08-10 20:32 2人阅读 评论(0) 收藏

    Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16539 Accepted: 3605 ...

  6. poj2391 Ombrophobic Bovines 拆点+二分法+最大流

    /** 题目:poj2391 Ombrophobic Bovines 链接:http://poj.org/problem?id=2391 题意:有n块区域,第i块区域有ai头奶牛,以及一个可以容纳bi ...

  7. POJ2391:Ombrophobic Bovines(最大流+Floyd+二分)

    Ombrophobic Bovines Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 21660Accepted: 4658 题目 ...

  8. POJ2391 Ombrophobic Bovines(网络流)(拆点)

                         Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  9. BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

    一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...

随机推荐

  1. zencart用chrome无法登录后台

    再本地安装完zencart后,可以使用ie和Firefox登录网站后台,但是使用chrome登录时,页面闪一下,然后又跳转到登录页面. 按如下设置可以解决该问题: 中文版:商店设置->Sessi ...

  2. 史上最全Vim快捷键键位图(入门到进阶)

    经典版 下面这个键位图应该是大家最常看见的经典版了. 对应的简体中文版 其实经典版是一系列的入门教程键位图的组合结果,下面是不同编辑模式下的键位图. 入门版 基本操作的入门版. 进阶版 增强版 下图是 ...

  3. windows服务器记录3389远程桌面IP策略

    以下代码复制存成一个批处理文件后双击即可! 3389IP日志路径是C:\WINDOWS\PDPLOG\RDPlog.txt  代码: MD C:\WINDOWS\PDPLOG  " /f  ...

  4. mysql列属性auto(mysql笔记四)

    常见的的是一个字段不为null存在默认值 没值得时候才去找默认值,可以插入一个null到 可以为null的行里 主键:可以唯一标识某条记录的字段或者字段的集合 主键设置 主键不可为null,声明时自动 ...

  5. phpcms后台部分修改

    1.后台登陆前提示信息取消及成功后提示信息取消.    (1)后台登陆前提示信息取消               phpcms\modules\admin\classes\admin.class.ph ...

  6. dump buffer cache

    1.基础内容: ALTER SESSION SET EVENTS 'immediate trace name buffers level n'; n取值意义: 1 只转储buffer header. ...

  7. 第十八章 数据访问(In .net4.5) 之 I/O操作

    1. 概述 本章内容包括 文件操作.流操作.读写网络数据 以及 异步I/O操作. 2. 主要内容 2.1 文件操作 ① 使用 Drive 和 DriveInfo 访问磁盘信息. DriveInfo[] ...

  8. Python 网页投票信息抓取

    最近学习python,为了巩固一下学过的知识,花了半天(主要还是因为自己正则表达式不熟)写了个小脚本来抓取一个网站上的投票信息,排名后进行输出. 抓取的网站网址是http://www.mudidi.n ...

  9. [转载]--类unix系统如何初始化shell

    Shell的配置文件 当我们在linux中打开一个shell的时候,系统会读取相关的配置文件来初始化shell(其他unix-like OS也一样).配置文件包括以下这些: 1. 全局配置(对所有用户 ...

  10. .Net码农学Android---五分钟了解布局

    在android中应用的界面是以xml来组织的,这一点和WPF相似,通过配置xml文件我们可以灵活的构建出你自己想要的界面. 而在所有的xml界面文件中,根节点必须是布局,即先有布局,然后在布局中组织 ...