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. 在peopletools里面测试文件上传

    Using the PeopleTools Test Utilities Page Select selectPeopleTools, then selectUtilities, then selec ...

  2. MVC5 Identity 用用户名登录而不用电子邮件

    1.修改AccountViewModels ·修改RegisterViewModel public class RegisterViewModel { [Required] [Display(Name ...

  3. Java基本开发环境搭建(适合第一次使用)

    Java基本开发环境搭建(适合第一次使用) 编写人:cc 阿爸 2013-10-17 一.开发工具获取 1.开发工具包JDK l  下载地址: 到ORACLE公司官方网站(http://www.ora ...

  4. Emmet用法

    Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: ...

  5. 学习c的第8天

    #include <stdio.h> int main() { char ch; printf("请输入分数等级(A,B,C,D):"); scanf("%c ...

  6. mysql给root开启远程访问权限,修改root密码

    1.MySql-Server 出于安全方面考虑只允许本机(localhost, 127.0.0.1)来连接访问. 这对于 Web-Server 与 MySql-Server 都在同一台服务器上的网站架 ...

  7. php生成excel文件的简单方法

    生成excel文件,最简单的莫过于把数据库的数据导入到excel就行了. 生成excel 当然使用的是 phpExcel http://www.jbxue.com/tags/phpexcel.html ...

  8. 通过API函数来控制SQLite数据库增删改查

    person类属性有Intenger id,String name,Intenger  age,相应的构造方法和set get方法. package com.xh.tx.dao; import and ...

  9. DevExpress LookUpEdit和ComboBoxEdit部分用法

    LookUpEdit 1.绑定列 (注意点:LookUpEdit1的FieldName要和绑定的列明一致) 方式一: LookUpEdit1.Properties.DisplayMember = &q ...

  10. C#使用SQL存储过程完整流程

    存储过程就是固化在SQL数据库系统内部的SQL语句,这样做的好处是可以提高执行效率.提高数据库的安全性.减少网络流量.接下来就讲解如何在数据库中建立一个存储过程. 打开SQL2055数据库,展开“数据 ...