Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17554 | Accepted: 3846 |
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
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.
题意:有n块田地,已知每块田地上面牛的数量和雨篷能遮蔽的牛的数量;有m路无向边连接任意两块田地,每条路有固定的长度。问如果下雨了,所有的牛要怎么走,才能使得在最短的时间(最后的牛进入雨篷)内让所有的牛进入雨篷,如果不能的话输出-1。
解题思路:首先Floyd算法求出任意两点间的最小距离,接着二分枚举时间T,这道题出现了牛的数目和雨棚的容量,所以干脆把i拆成i'和i''一个代表牛的数目,一个代表雨棚的容量,只要dis[i][j] <= limit,i和n+j之间有一条无穷大的边,接着跑一次最大流,判断最大流是否等于牛的总数,这里的limit是用二分枚举的。