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. CSS中属性position位置详解功能讲解与实例分析

    position有五个值:static.relative.absolute.fixed.inherit. static 是默认值.就是按正常的布局流从上到下从左到右布局,平常我们做网页制作时,没有指定 ...

  2. tomcat目录简介

    http://www.cnblogs.com/kerrycode/p/3588816.html 主目录下面有bin.lib等目录 bin 存放Tomcat启动.停止服务程序以及一些其他脚本程序 lib ...

  3. JS限定手机版中图片大小随分辨率自动调整

    <script type="text/javascript"> var ObjImg = jQuery(".Dy_Content img"); fo ...

  4. 获取屏幕分辨率(C/C++)

    C/C++获取屏幕分辨率的方法 int main(int argc, char* argv[]) { // 需要添加头文件: // #include <Windows.h> system( ...

  5. 利用脚本修改SQL SERVER排序规则

    利用脚本修改SQL SERVER排序规则 编写人:CC阿爸 2014-3-1 l  今年的一项重要工作是对公司所用系统进行繁简的转换,程序转成简体基本很容易解决,但数据库转换成简体,就没那么容易了.经 ...

  6. VS2010在非IE浏览器下调试Silverlight程序

    以Chrome为例: 第一步:在程序中设置断点. 第二步:右键点击web应用程序的起始页(.html或.aspx文件),选择"浏览方式",选中Chrome或其它非IE浏览器,点&q ...

  7. .Net之美

    第1章 C#类型基础 1.1 值类型和引用类型值类型和引用类型是以它们在计算机内存中是如何被分配的来划分的.值类型包括了结构和枚举,引用类型则包括了类. 接口. 委托等. 还有一种特殊的值类型,称为简 ...

  8. c#反射机制学习和利用反射获取类型信息

    反射(Reflection)是.NET中的重要机制,通过放射,可以在运行时获得.NET中每一个类型(包括类.结构.委托.接口和枚举等)的成员,包括方法.属性.事件,以及构造函数等.还可以获得每个成员的 ...

  9. 数据结构学习笔记05图(最小生成树 Prim Kruskal)

    最小生成树Minimum Spanning Tree 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边. 树: 无回路   |V|个顶 ...

  10. 配置github上的SSH key及上传自己的项目到github

    这篇文章比较好,链接如下:http://www.jianshu.com/p/b81eeb5d7858 需要指出的几点:1.