poj2391 最大流+拆点+二分答案+Floyd

Ombrophobic Bovines

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 19553   Accepted: 4217

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

嗯。。解法rt
时间: 2024-10-30 22:17:03

poj2391 最大流+拆点+二分答案+Floyd的相关文章

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

poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 15时39分22秒 * File Name: poj2391.cpp */ #include <ctime> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring&g

【Luogu】P3705新生舞会(费用流+分数规划+二分答案)

题目链接 本来以为自己可以做出来,结果……打脸了 (貌似来wc立了好几个flag了,都没竖起来) 不过乱蒙能蒙出一个叫“分数规划”的东西的式子还是很开心的 观察$C=\frac{a_{1}+a_{2}+.......+a_{n}}{b_{1}+b_{2}+.....b_{n}}$ 然后可以把分母乘到左边 然后可以把C乘进去 然后二分C,建图求最大权匹配,判断跟答案的关系. #include<cstdio> #include<cstdlib> #include<cctype&g

POJ--2391--Ombrophobic Bovines【拆点+Floyd+Dinic优化+二分答案】网络最大流

链接:http://poj.org/problem?id=2391 题意:有f个草场,每个草场当前有一定数目的牛在吃草,下雨时它可以让一定数量的牛在这里避雨,f个草场间有m条路连接,每头牛通过一条路从一点到另一点有一定的时间花费,现在要下雨了,农场主发出警报牛就会立即去避雨.现在告诉每个草场的情况,以及m条边的信息.农场主至少需要提前多久发出警报才能保证所有牛都能避雨?如果不是所有牛都能成功避雨输出-1. 思路:这道题需要拆点,是看到魏神的博客才知道的,我们把原图拆成一个二分图,避免突破最大距离

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

一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 shelter 点, 然后对于每个 farm x : S -> cow( x ) = cow( x ) 数量 , shelter( x ) -> T = shelter( x ) 容量 ; 对于每个dist( u , v ) <= m 的 cow( u ) -> shelter( v

POJ 2391--Ombrophobic Bovines【拆点 &amp;&amp; 二分 &amp;&amp; 最大流dinic &amp;&amp; 经典】

Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16460   Accepted: 3593 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 h

BZOJ 1305 CQOI2009 dance跳舞 二分答案+最大流

题目大意:给定n个男生和n个女生,一些互相喜欢而一些不.举行几次舞会,每次舞会要配成n对.不能有同样的组合出现.每一个人仅仅能与不喜欢的人跳k次舞,求最多举行几次舞会 将一个人拆成两个点.点1向点2连一条流量为k的边.两个人若互相喜欢则点1之间连边,不喜欢则点2之间连边 对于每个要验证的x值 将每个人的点1向源或汇连一条流量为x的边 然后二分答案跑最大流就可以 #include<cstdio> #include<cstring> #include<iostream> #

POJ 2112 Optimal Milking 二分答案+最大流

首先二分最长的边,然后删去所有比当前枚举的值长的边,算最大流,看是否能满足所有的牛都能找到挤奶的地方 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include

POJ--2112--Optimal Milking【Floyd+Dinic+二分答案】

链接:http://poj.org/problem?id=2112 题意:有k个挤奶器,编号1~k,c头牛,编号k+1~k+c,每个挤奶器最多能给m头牛挤奶,给你一个k+c的邻接矩阵,要求每头牛都能挤奶并且要求c头牛需要走的所有路程中的最大路程最小,求这个最小的路. 思路: 1. 先用floyd处理出多源最短路 2. 用二分枚举答案的可能,初始上限应该为(200+30)*200,但是我这么开T了,可能因为代码太挫,改到1000,卡着时间过了,只能说poj数据弱了.后来看别人的代码,和我的做法一样

HDU3081Marriage Match II(二分答案+并查集+最大流SAP)经典

Marriage Match II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2507    Accepted Submission(s): 856 Problem Description Presumably, you all have known the question of stable marriage match. A