#P6768. [USACO05MAR] Ombrophobic Bovines 发抖的牛
[USACO05MAR] Ombrophobic Bovines 发抖的牛
Description
FJ’s cows are very afraid of getting rained on, which makes them shiver. They plan to install a rain alarm and arrange an evacuation plan. They need to compute the minimum time needed to get all cows into shelters.
The cows graze on fields on the farm. There are bidirectional roads connecting these fields. The roads are wide, so an unlimited number of cows can pass through them. Each field has a shelter with a certain capacity, and cows can enter the shelter on the same field instantly.
Compute the minimum time so that every cow can enter a shelter.
Input Format
Line : two integers and .
Lines to : on line , there are two integers describing field . The first is the number of cows on the field, and the second is the shelter capacity on that field. Both integers are between and .
Lines to : each line contains three integers describing a road: the two endpoints, and the time needed to travel along this road (between and ).
Output Format
One integer, the minimum time. If it is impossible to get all cows into shelters, output .
3 4
7 2
0 4
2 6
1 2 40
3 2 70
2 3 90
1 3 120
110
Hint
Constraints: for of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号