#P2176. [USACO11DEC] RoadBlock S / [USACO14FEB] Roadblock G/S
[USACO11DEC] RoadBlock S / [USACO14FEB] Roadblock G/S
Description
Every morning, FJ walks from his house across the farm to the barn. The farm consists of fields connected by bidirectional roads, each with a certain length. FJ’s house is at field , and the barn is at field . No two fields are connected by multiple roads, and the graph is connected. Whenever FJ travels between fields, he always takes a path with the minimum total length.
FJ’s cows, up to no good as always, decide to disrupt his morning routine. They place a stack of hay bales on one of the roads, doubling that road’s length. The cows want to choose a road to maximize the increase in FJ’s shortest path distance from home to the barn. They ask you to compute and report this maximum increase.
Input Format
Line : two integers .
Lines to : the -th line contains three integers . and are the indices of the fields connected by road , and is the length of that road.
Output Format
A single integer: the maximum increase obtained by doubling exactly one road.
5 7
2 1 5
1 3 1
3 2 8
3 5 7
3 4 3
2 4 7
4 5 2
2
Hint
Sample explanation: If the length of the road between and is doubled, the shortest path changes from to .
Constraints:
- For of the testdata, , .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号